Dynamically defined setter methods using define_method?

Posted by nicosuria on Stack Overflow See other posts from Stack Overflow or by nicosuria
Published on 2010-03-23T10:55:09Z Indexed on 2010/03/23 11:23 UTC
Read the original article Hit count: 285

I use a lot of iterations to define convenience methods in my models, stuff like:

PET_NAMES.each do |pn|
define_method(pn) do
...
...
end

but I've never been able to dynamically define setter methods, ie:

def pet_name=(name)
...
end

using define_method like so:

define_method("pet_name=(name)") do
...
end

Any ideas? Thanks in advance.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby