ruby

is this a valid ruby syntax ?

if step.include? "apples" or "banana" or "cheese" say "yay" end ...

goto command in ruby ?

is there a way to start at a specified line ? like a goto command ? ...

Ge the most recent date from a list - Ruby

I have an array of Ruby Date objects. How can I find the most recent datetime and the oldest datetime? thanks ...

For the first x in array?

I imagine this has a rather simple answer <% for user in @users %> <li> <%= link_to user.username, user %> </li> <% end %> Taking my simple example above, how would I apply a class to my <li> to the first three instances returned? Secondly, how could I just have the the second two items have a different class from the first o...

Ruby - FlexMock Backticks Method

I have Ruby code that uses the backticks in a number of spots and want to test it out. I'm using FlexMock and want to mock that method somehow. I know the method is Kernel, :` but can't seem to get it to work with FlexMock. How would you do this? Here's a sample of a method I want to test: def foo result = `ls` if result.to_a.length...

How can I find the names of argument variables passed to a block

Im trying to do some metaprogramming and would like to know the names of the variables passed as block arguments: z = 1 # this variable is still local to the block Proc.new { |x, y| local_variables }.call # => ['_', 'z', x', 'y'] I am not quite sure how to differentiate between the variables defined outside the block and the bloc...

Is there any Python module similar to Distributed Ruby

I am new to Python. Just want to know is there any module in python similar to ruby's drb? Like a client can use object provided by the drb server? ...

Rails: mysql & postgres at the same time in the same app?

Why you may ask? Because i have built the app on mysql and need to start using postgres for GIS component of my app only. Eventually i will migrate to postgres completely but in the mean time would like to know if this is possible ...

Regular delayed jobs

Hello, I'm using Delayed Job to manage background work. However I have some tasks that need to be executed at regular interval. Every hour, every day or every week for example. For now, when I execute the task, I create a new one to be executed in one day/week/month. However I don't really like it. If for any reason, the task isn't co...

Debugging Ruby's garbage collection

I'm having problems with a long-lived background ruby process on our server, which isn't cleaning up Tempfiles. I'm using hijack to inject into the process & inspect things, using, for example, ObjectSpace.each_object(ActiveRecord::Base){|o| puts o} - turns out that the Tempfiles in question are being referenced by an instance of one ...

Does Ruby have an addon similar to Perl 6 grammars?

Perl has been one of my go-to programming language tools for years and years. Perl 6 grammars looks like a great language feature. I'd like to know if someone has started something like this for Ruby. ...

Sending USR2 to mongrel_rails sometimes results in an "Address already in use" on the restart

We have a rolling-restart mode for our mongrel cluster that sends a USR2 signal to each running process. This works great, most of the time. But very occasionally the mongrel process will shutdown, and then fail to restart, with the following error: /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/tcphack.rb:12:in `...

efficiently storing "answers"

I'm building out an Answer ActiveRecord class that can have different types of answers. That is, the answer could be an integer, float, date, string... whatever... The way I see it there are two ways to store the answers 1) Have an attribute named "value" that is serialized. This is nice since you can always access the answer from ...

Convert two-digit year to four-digit year in Ruby

I have strings like "84", "03" etc. that I want to convert to Date objects, but Date.new only takes the expanded 4-digit year as a parameter. I know it's simple to do, but I don't want to reinvent this wheel. Is there something that does this already? Either in standard Ruby or in ActiveSupport. ...

Any Full "Ruby Stack" AMI on EC2 ?

What is best available EC2 AMI that have satisfy following must have? Ruby Stack Pre Installed MySql Installed and configured with Ruby Monit Installed Nginx Secure SSH access Please let me know AMI you are recommending you have used or not? Amazon lacks proper review system for AMI unlike product/book previews. ...

Ruby: count the number of 1's in a binary number

I have a binary number (52 bits) represented as a string "01100011...." What would be the quickest way to count the number of 1's? "01100011....".count("1") obviously works but is quite time consuming if this operation needs to be done thousands of times. ok, some more info. I am trying to create bit vectors for words as follows de...

Using rails named routes within custom rendered ERB templates

I have a method on an active record class that renders an ERB template for a messaging system. The simplified code looks like this: ERB.new(template).result(binding) where binding is the current Binding of the ActiveRecord model object and template is an erb template file read in from the file system. I would like to use some named...

Protecting Ruby Code

I'm developing a commercial project on an ARM based embedded board with a custom Linux kernel on it, using Ruby. Target workspace of the project and the device is a closed-environment, no ethernet, inernet, I/O devices etc... I want to protect my code/program so that; it'll only work on the specific machines I let (so; people cant just c...

Turning a Hash of Arrays into an Array of Hashes in Ruby

We have the following datastructures: {:a => ["val1", "val2"], :b => ["valb1", "valb2"], ...} And I want to turn that into [{:a => "val1", :b => "valb1"}, {:a => "val2", :b => "valb2"}, ...] And then back into the first form. Anybody with a nice looking implementation? ...

SQLite3 helper?

Is there any application like SQL Buddy for SQLite3 for Mac. I am just starting with Ruby on Rails and have my environment set up on my Mac running Snow Leopard, I have used SQL Buddy before and I was wondering if anyone knows anything like that for SQLite3. ...