Sending methods after classifying

The following code gives me an error:
class_vars = [‘fruit’,‘cow’,‘coffee’].each do |class_var|
“#{class_var}”.classify.send(:find, 1 + rand(10))
end

The error message stack:
LocalJumpError: no block given
from (irb):34:in find' from (irb):33:ineach’
from (irb):33:in find' from (irb):33:insend’
from (irb):33
from (irb):32:in `each’
from (irb):32
from :0

What I am trying to do here is, convert a string to an ActiveRecord
class and then send a AR method like find to it. But it doesn’t work.
I have all the classes defined.

Any idea why this is happening?

On 29 Dec 2007, at 12:21, Love AJAX wrote:

   from (irb):33:in `find'
   from (irb):33:in `send'
   from (irb):33
   from (irb):32:in `each'
   from (irb):32
   from :0

What I am trying to do here is, convert a string to an ActiveRecord
class
If you just poke around in the console you’ll see that
‘fruit’.classify #=> ‘Fruit’
That’s a string, not a Class (i.e. classify is just a string
transformation that camelcases or whatever is has to do).
You can use constantize to actually get the class you’re talking about.

Fred

It works. Thanks a lot. I should have tried this one.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs