ruby

Calling self.send iteratively on a hash argument to initialize()

I'm trying to understand the following Ruby code. It looks like attrs is a hash that gets passed as an argument with a default value of an empty hash. Then attrs.each iterates over the key, value pairs in the hash (|k,v|). What effect is achieved by calling self.send on the elements of the key value pair during this iteration? def in...

Does self.class.delete call a class method?

I'm looking at this code in a Ruby library. Am I correct in assuming that self.class.delete calls the class method called delete on the current object - i.e. the object referenced by self. def delete! self.class.delete(self.key) end ...

What should I learn? Python or Ruby?

Possible Duplicate: Should I learn Ruby or Python? Hi guys. I am a PHP developer so, mainly a web developer, and I'm used to work with MVC. I use CakePHP, which is a powerful PHP framework to develop web apps and such. I'm comming from the web scene and I really want to keep my work on the web but I also would like to learn a n...

"base.send :include, InstanceMethods" ---> What does this do?

I'm looking at a module X which contains two modules called "InstanceMethods" and "ClassMethods". The last definition in module X is this: def self.included(base) base.send :include, InstanceMethods base.send :extend, ClassMethods end What does this do? ...

self.class_eval <<DEF ... DEF

I'm trying to understand this function. What I can see is an attribute and type are passed to the opal() method. Then type_name takes its value from type as long as type is a Symbol or String. Otherwise, the name method is called on type. I imagine the name method is similar to the class method to get the class of the type argument. A...

Are server restarts necessary while developing an App Engine/Java project in Eclipse?

I'm developing a Ruby web application on top of GAE-Java and development is painfully slow because in Eclipse I must restart the development server every time I make a change to my Ruby code. I'm not able to work effectively this way because each restart takes about a minute. Is the norm for Java development or am I doing something wron...

How could I download an mms audio stream in Ruby?

Hi, I would like to access an mms:// url, and stream the file in ruby. For example, in the same way that Net:HTTP works for http:// type urls. ...

how can I simply merge a hash into a new one?

I have a simple hash like so { "1234" => "5", "2345" => "6" } How can I create a new hash with both the keys and values in side it? Like so: { key_id = "1234", value_id = "5" }, { key_id = "2345", value_id = "6" } ...

Converting a Ruby String into an array.

I have a string "1,2,3,4" and I'd like to convert it into an array: [1,2,3,4] How? ...

Ruby on Rails Country/State Select Enigma

I am trying to implement something seemingly very simple, and I have been beating my head against it for days at this point. My desired end result is a Country select drop-down, tied to a State select drop-down, in such a way that when a given country is selected, IF states are known THEN those states are displayed in a select drop down...

Flickr gem : how to access user details?

http://github.com/ctagg/flickr/tree/master I'm trying the example in the home page of the flickr gem. require 'flickr' flickr = Flickr.new('MY_KEY') user = flickr.users('[email protected]') user.name user.location while I'm able to get the user object, I can't get any of the other attributes like...

Ruby on Rails: what does "equals" symbol mean as a parameter?

Some open source I've been using has the below line as a function declaration: def parse_query(query=nil, options={}, models=nil) What effect do the "equals" symbols have on the statement? Does it just make the parameters optional? ...

Ruby is_a? problems

I have a constructor for an object Program that validates an argument to make sure it is an integer: def initialize(programid,*other_args) unless programid.is_a?(Integer) then raise TypeError end @programid = programid @name = other_args['name'] end and when I create a new instance my_prog = Program::new(13453) It give...

rails: how to link values in data migrations to class/model variables?

my sql DB contains tables "jobs" and "job_categories." "job_categories" associates job category strings (i.e. "Software Development") with an integer number (i.e. 7). I need these associations saved into variables in my job controller for various query functions. How can I use rails to dynamically link changes to the job_categories tab...

Maintaining Persistence When Using Rake Tasks

I'm running some basic continuous integration scripts in the form of rake tasks, using cron to automate their running. I'd like to be able to maintain some form of state between tasks however. I've considered just writing information to a file and reading it back in. Is there a more "ruby" way of doing this? ...

What's a nice clean way to use an options hash with defaults values as a parameter in ruby

Let's say I want a method which will be called like this: tiger = create_tiger( :num_stripes => 12, :max_speed => 43.2 ) tiger.num_stripes # will be 12 where some of the options have default values: tiger = create_tiger( :max_speed => 43.2 ) tiger.num_stripes # will have some default value what's a nice idiomatic ruby way of im...

What's the best background job management library for Rails?

It's been a while since I've last used backgrounding in Rails. I've use backgroundrb and bj before. Is there anything else that manages background tasks better? ...

my rails ApplicationController is having a RoutingError

I am by no means a Ruby developer, but I code HAML for a ruby framework on my localhost. I had originally put a file called vidgirlBox2.flv file and called to it within the HAML, but converted the file to a swf called vidGirl_home.swf . This swf worked. Until I made a simple change to the orginal .fla, and overwrote the vidGirl_home...

Reverse engineering a statistics data file from my insulin pump controller

This may or may not be a grey area subject, though my intentions are certainly not, so my intention is not to stir up an ethical debate on the topic of reverse engineering. I'm a type 1 diabetic currently undergoing pump therapy. I'm an OmniPod user, it's a disposable pod that adheres to my body and dispenses insulin for 3 days. It'...

SQL: how to find a complement to a set with a derived function/value

This one has me stumped, so I'm hoping someone who's smarter than me can help me out. I'm working on a rails project in which I've got a User model which has an association of clock_periods joined to it, having the following partial definition: User has_many :clock_periods #clock_periods has the following properties: #clock_i...