Hi all,

ROR newbie coming from a PHP background here.

I have a model that inherits from ActiveRecord::Base. I would like to
extend that into two further models, to separate functionality from
each other. Basically:

class Person < ActiveRecord::Base
  attr_accessible :gender
end

class Male < Person

end

class Female < Person

end

How can I write a method within Person that will detect what gender
has been defined and return the proper object based on it?

I'm thinking something like...

def self.new
  gender_class = self.gender == 'Female' ? 'Female' : 'Male'
  eval(gender_class).new
end

In that version, though, "self.gender" isn't recognized. I'm sure I'm
missing something really basic, but can someone point out what it is?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to