ruby

What is the best way to write to a file in Ruby?

I would like to write some data to a file in Ruby. What is the best way to do that? ...

Problem installing RubyGems on Vista

I get the following error when attempting to install RubyGems. I've tried Googling but have had no luck there. Has anybody encountered and resolved this issue before? C:\rubygems-1.3.0> ruby setup.rb . . install -c -m 0644 rubygems/validator.rb C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/validator.rb install -c -m 0644 rubygems/version.rb ...

How do I implement Section-specific navigation in Ruby on Rails?

I have a Ruby/Rails app that has two or three main "sections". When a user visits that section, I wish to display some sub-navigation. All three sections use the same layout, so I can't "hard code" the navigation into the layout. I can think of a few different methods to do this. I guess in order to help people vote I'll put them as ans...

Adding an instance variable to a class in Ruby

How can I add an instance variable to a defined class at runtime, and later get and set its value from outside of the class? Edit: It looks like I need to clarify that I'm looking for a metaprogramming solution that allows me to modify the class instance at runtime instead of modifying the source code that originally defined the class. ...

Difference between a class and a module

I came from Java and now I am working more with ruby. One language feature I am not familiar with is the module. I am wondering what exactly is a module and when do you use one? Also why use a module over a class? ...

How can I get the FQDN of the current host in Ruby?

I need to get the fully expanded hostname of the host that my Ruby script is running on. In Perl I've used Sys::Hostname::Long with good results. Google seems to suggest I should use Socket.hostname in ruby, but that's returning just the nodename, not the full hostname. ...

JRuby on Rails vs. Ruby on Rails, what's difference?

I'm looking to try out JRuby and JRuby on Rails. I'm having trouble finding information on what's difference between JRuby on Rails and Ruby on Rails. What's the differences I need to look out for? ...

Open the default browser in Ruby

In Python, you can do this: import webbrowser webbrowser.open_new("http://example.com/") It will open the passed in url in the default browser Is there a ruby equivalent? ...

RoR: nested namespace routes, undefined method error

I am working on the admin section of a new rails app and i'm trying to setup some routes to do things "properly". I have the following controller: class Admin::BlogsController < ApplicationController def index @blogs = Blog.find(:all) end def show @blog = Blog.find(params[:id]) end ... end in routes.rb: map.namesp...

What to learn first?

I went to school for programming years ago and when I got out I found a job in system administration and that is the direction my career took. I'd like to get back into development of some sort and have been 'playing' with C# and ASP.NET, but I've been hearing lots of buzz for other 'new' languages (by new I mean that they are new to me)...

From objects to tables using activerecord

Hi all, I'm getting some objects from an external library and I need to store those objects in a database. Is there a way to create the tables and relationships starting from the objects, or I have to dig into them and create migrations and models by hand? Thanks! Roberto ...

When would you NOT want to use memcached in a Ruby on Rails app?

Assuming a MySQL datastore, when would you NOT want to use memcached in a Ruby on Rails app? ...

Implementing a replacement for Ruby's IO.popen() and system()

IO.popen() and system() in Ruby is sorely lacking several useful features, such as: obtaining the return value of the function capturing both stdout and stderr (seperately and merged) running without spawning an extra cmd.exe or /bin/sh process Python has a module "subprocess" which I was thinking about using as inspiration for a sim...

Ruby / Perl / Python / etc. tutorial site - only code

A few weeks ago I've run into a site that had tutorials for many languages including Perl, Ruby, Python. The concept was that it basically showed you the code itself of the given language and taught you like that, so the whole tutorial was a great amount of code and some comments in it. The only problem is that I forgot to bookmark it an...

Connection error for sqlserver rake db:migrate

I am getting the following error: Open OLE error code:80004005 in Microsoft OLE DB Provider for SQL Server [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. HRESULT error code:0×80020009 Exception occurred. I have tried following the directions here with no luck: http://wiki.rubyonrails.org/rails/pag...

Capistrano not restarting Mongrel clusters properly

I have a cluster of three mongrels running under nginx, and I deploy the app using Capistrano 2.4.3. When I "cap deploy" when there is a running system, the behavior is: The app is deployed. The code is successfully updated. In the cap deploy output, there is this: executing "sudo -p 'sudo password: ' mongrel_rails cluster::restar...

What is "for" in Ruby

In Ruby for i in A do # some code end is the same as A.each do |i| # some code end for is not a kernel method. What exactly is "for" in ruby Is there a way to use other keywords to so the similar things? Something like total = sum i in I {x[i]} mapping to total = I.sum {|i] x[i]} ...

Notification of object destruction in Ruby

I have written a custom Rails model. This model is backed by an actually server not by a database table (so it does not inherit from ActiveRecord::Base). In order to get the requested information from the server I open a SSH connection to it. Because rails does not reuse object a new object, as well as a new SSH connection to the serv...

What is the difference between include and extend in Ruby?

Just getting my head around Ruby metaprogramming... the mixin/modules always manage confuse me everytime. include : mixes in specified module methods as instance methods in the target class extend : mixes in specified module methods as class methods in the target class So is the major difference just this or is a bigger dragon lurki...

Method access in Ruby

How is it that Ruby allows a class access methods outside of the class implicitly? Example: class Candy def land homer end end def homer puts "Hello" end Candy.new.land #Outputs Hello ...