ruby

Does Ruby have a Metaobject protocol and if not, is it possible to implement one?

Pardon my ignorance, but What is a Metaobject protocol, and does Ruby have one? If not, is it possible to implement one for Ruby? What features might a Metaobject protocol possess if Ruby was to have one? ...

How can I call an older version of a gem from the commandline?

Say I have two versions of a gem installed (somegem versions 0.10.6 and 0.10.5) and I want to run the earlier version from the commandline. Do I have to uninstall the newer version? Is there a way I can use a flag to specify which version I want to use? Something like... somegem /path/to/dir --version 0.10.5 I checked the rubygems do...

Iteratively filling an array with hashes from an each/do block gives me all repeat values..help!

I am trying to fill an array of hashes with hashes created through an each loop, If I print each individual hash within the iteration they are distinct, but when I try to push them to an array, the resulting array has the last hash repeated whatever number of times. Here's the code: def get_tweets tweet_array = Array.new tweet = {} ...

How to store complex data struts in Memcache

I have a data struts like this: category: subcategory: color:red name:pen Is there any better method to store if i want to load such data in memcache? or Is there any other better memory database? Thanks! ...

How connect to db depending on @request.host value?

How connect to different db depending on @request.host value? Using Sinatra and MongoDB with Mongoid. I need to read a Sintra application's menu, data ... from different databases. I wish to deploy it only in one place and depending on request.host(subdomain) value to serve the specific pages. ...

Rails method - to_sym

What does the to_sym method do? What is it used for? ...

How to use Ruby CLI client to launch a JobFlow based on a JSON JobFlow description on Amazon Elastic MapReduce.

I have written a mapreduce application for hadoop and tested it at the command line on a single machine. My application uses two steps Map1 -> Reduce1 -> Map2 -> Reduce2 To run this job on aws mapreduce, I am following this link http://aws.amazon.com/articles/2294. But I am not clear how to use Ruby CLI client provide by amazon to do al...

Chaining string methods (split, gsub) in Ruby

I'd like to split and do a substitution in a string in one chained command. Here's my example including the error message: >> filebase => "Ueki_-_Hello_World" >> filebase.split("_-_").gsub("_"," ") NoMethodError: private method `gsub' called for ["Ueki", "Hello_World"]:Array from (irb):16 It works when I save the result of "split...

Space in the ruby array by %w

How can i add space character in the ruby array if i want to use %w(a b c) syntax? ...

Where Should Collision Detection Code Be?

Hi guys, I'm writing a pong game and I have a ball class that has velocity x, y, positions and all that stuff that every frame is updated by calling @ball.update, this moves the ball forward by its x_vel and Y_vel etc. My question is Should my collision code be in the loop or in the update method of the ball class? Or should it all be in...

web based games done in ruby, point me in the right direction

So I've been using a number of educational software web based apps, they are games, and they are all using flash. Recently I've seen some posts about making games with ruby. Are there any good examples out there for making games with ruby. I know of the game library, and then there is one book on amazon that has some awful reviews, and t...

Rails 3 Routing Error - "No Route Matches"

I'm following along with the O'Reilly Rails book, but it's created for Rails 2, so I think that's where the error lies. In app/views/entries/sign_in.html.erb: <html> <head><title>Hello <%=h @name %> </title> </head> <body> <h1> Hello <%=h @name %></h1> <%= form_tag :action => 'sign_in' do %> <p>Enter your name: <%= text_field_ta...

Is there a stylecop equivalent for Ruby?

StyleCop is a tool that analyzes C# source code to enforce a set of style and consistency rules. Is there anything similar for the Ruby language? ...

sqlite3 db is locked

I am on Ubuntu10. Create new db file with touch development.db Want my migrations rake db:migrate but get locked error SQLite3::BusyException: database is locked How it can be locked?! update it can be locked by samba. it's shared folder ...

Ruby / Rails - .each Iterator is printing entire array at the end of the loop.

I think what I'm trying to do is pretty simple, and I'm really not sure why this isn't working. I'm using Rails 3. Essentially, I'm just trying to select the distinct values from a column in an existing model, and print them out all. For the most part, this works but the .each loop in my view also ends up printing the entire array at t...

How can I make my Ruby script (not Rails) run anywhere?

Hello, I'm very new to Ruby. I've recently finished writing a simple script, which uses a bunch of gems. It works well on my own workstation. When I copied the script over to my laptop, it stopped working, even though I manually installed all the gems. I think it may be due to version differences in the gems installed, but I wanted to ...

ruby csv::writer - encapsulate field

The issue: I am writing out some CSV data using "csv::write". Some other software I am using does not read the data correctly, such that the second record of this data will not interpret the double quotes as an escaped quote: 1,"Sometimes my ""name"" is Joe, and sometimes it is not." 2,I might ""like"" jam! Is there a way I can force ...