ruby

Shoulda: unknown error with validates_each

I'm having an awful time trying to understand what my validation method is having trouble with. I installed shoulda and when I tried to use it it errors out with a strange undefined method NoMethodError: undefined method '[]' for false:FalseClass which is very odd. I narrowed it down to this piece of offending code: validates_each :na...

Parse js arrays in ruby

Hi All, i've js file that holds Array objects and data assigns var A_1_val = new Array(7); var B_1_txt = new Array(7); A_1_val[0] = '111'; B_1_txt[0] = 'utf8_content'; A_1_val[1] = '222'; B_1_txt[1] = 'bar'; etc.. need to get these arrays in ruby. found http://github.com/jbarnette/johnson, but it can't correctly return a...

Ruby gems won't load even though installed

I know there's similar questions on SO, but none of them solve my problem... The gist of it is that I can't get gems to load on a clean Ruby 1.9.1 install on Ubuntu 10.04: :~/$ irb irb(main):001:0> require 'rubygems' => false irb(main):002:0> require 'cassandra' LoadError: no such file to load -- cassandra from (irb):1:in 'require'...

How to create video,audio chat system in rails,ruby or using node

I want to build video/audio chat application for my one of the social apps.Is there any library are available in java or ruby or node.js that can help us to build audio/video chat application. Or any suggestion/technical article that help us to build video chat application. ...

using array difference ([array] - [other array] )with different, equivalent instances

I'm trying to use the difference method (array1 - array2), and it isn't working as expected. My unit test: a = DeepsEdge.new(Set[1,2]) b = DeepsEdge.new(Set[3,4]) c = DeepsEdge.new(Set[3,4]) assert a != b, "these are equal and should not be" assert_equal c, b assert_not_equal a, b assert_not_same c, b x = [a,b] y = [c] assert_equal x,...

A way to implement `String#split!`

Sometimes I need such method, which could change class of its own object. There are String#delete!, #downcase!, #encode!, #gsub!, #strip!, #slice!, etc. They are all trying to change string, but resulting class is anyway still String. And I want a method, which can convert String to Array. Some way to make this: irb(main):082:0> str = "...

State machine in Ruby using Fibers?

hello, I'm trying to get a handle on the new Fiber class in Ruby 1.9 and I read that one of the more common applications for Fibers (and coroutines) is in state machines. Unfortunately my Fiber-fu isn't up to much, so I was hoping one of you could show me a simple statemachine example in Ruby using Fibers thanks :) ...

How can I run something in a thread with passenger?

Hello, I'm using Phusion Passenger with my nginx to deploy rails/sinatra applications, and I'm currently having a problem. I want to run a class that checks for new submissions to reddit.com every 30 seconds. But since passenger shuts down the application after x seconds of idle time, it won't keep checking. Yes, I've tried to set pass...

accessing variables in loaded source while in irb

Say I have a file named test1.rb with the following code: my_array = [1, 2, 3, 4 5] Then I run irb and get an irb prompt and run "require 'test1'. At this point I am expecting to be able to access my_array. But if I try to do something like... puts my_array irb tells me "my_array" is undefined. Is there a way to access "my_array" ...

Ruby: How can i extract just one MYSQL record in Ruby instead all with each_hash do

I know how to get all Mysql Results from a table and output it with each_hash.do in Ruby like this results = con.query "SELECT * FROM table" #results.each_hash do |row| $url = row["Url"] $name = row["linkname"] $id = row["ID"] #end But how can i get only one record extracted from results? ...

How to find a hash key containing a matching value

Given I have the below clients hash, is there a quick ruby way (without having to write a multi-line script) to obtain the key given I want to match the client_id? E.g. How to get the key for client_id == 2180? clients = { "yellow"=>{"client_id"=>"2178"}, "orange"=>{"client_id"=>"2180"}, "red"=>{"client_id"=>"2179"}, "blue"=>...

is ruby on rails (or at least the community) dying?

This is an honest question and I am not trolling. As a newbie to rails I've been search for good rails resources. But I've been noticing many sites that apparently were once popular now being completely abandoned. Some examples: http://www.softiesonrails.com/ - last updated Feb 2010 http://www.therailsway.com/ - last updated Aug 2009...

named routes with devise in Rails 3 haml view

from rake routes I get this in my application new_admin_session GET /admins/sign_in(.:format) {:controller=>"devise/sessions", :action=>"new"} admin_session POST /admins/sign_in(.:format) {:controller=>"devise/sessions", :action=>"create"} de...

Ruby generators vs Python generators

Hi, I've been researching the similarities/differences between Ruby and Python generators (known as Enumerators in Ruby), and so far as i can tell they're pretty much equivalent. However one difference i've noticed is that Python Generators support a close() method whereas Ruby Generators do not. From the Python docs the close() meth...

Ruby or regex to strip excess line breaks

How would you turn this: Dear Fred How are you? Regards John Into this: Dear Fred How are you? Regards John Note: Single and double breaks are allowed, but no more than that. For example, we want to go from: "Dear Fred\n\n\n\nHow are you?\n\n\n\n\n\n\nRegards\nJohn" to "Dear Fred\n\nHow are you?\n\nRegards\nJohn" But...

Installing vim with ruby support (+ruby)

I'm trying to get command-t installed for vim but my current version of vim doesn't have the (+ruby) flag. The command "which ruby" shows that ruby is installed. What do I need to do in order to activate the +ruby flag in vim? Also, what does the +ruby flag technically mean? ...

using regular expressions in ruby to find a string in quotations

I am trying to construct a regex to find a string in ruby str = "foo" I want to be able to stop trying to find the string after it finds the closing quotation mark. I also want to keep the quotation marks so I can output the string I found as: puts "the string is:" + str => the string is: "foo" I am pretty new to using regular expr...

Ruby, How can i access local variables outside the do - end loop

I have a loop where i execute a series of command on a remote machine: ssh.exec('cd /vmfs/volumes/4c6d95d2-b1923d5d-4dd7-f4ce46baaadc/ghettoVCB; ./ghettoVCB.sh -f vms_to_backup -d dryrun') do|ch, stream, data| if #{stream} =~ /vmupgrade/ puts value_hosts + " is...

Correct way to make a DataMapper association

I want to have a table of users. These users shall have n contacts and n messages.. My code is: ... class User include DataMapper::Resource property :id, Serial, :key => true property :nickname, String has n, :contacts has n, :messages end class Contact include DataMapper::Resource belongs_to :user property :id, Se...

Ruby require 'file' doesn't work but require './file' does. Why?

I have a folder full of ruby files, and when I try and require one file in another that is in the same directory using require 'file' I get a LoadError but when I use require './file' everything works fine. Can somebody explain to me why this happens and if there is any way I can require a file without adding a ./ onto the file? (Pictur...