Question about model attributes

Hi,

At what point in rails are the methods for a models attributes
defined?

Because I have the following code: Parked at Loopia

And it returns in irb:

s = Playlist.find(:first).songs false 1

If I do this in irb: (The PlaylistItem model has an attribute
'position'

s = Playlist.find(:first).playlist_items[0].methods(true).include? ('position') true

How's that possible? Does irb do some fancy trick to retrieve all methods? Must I do something in the instance_eval to make the methods appear?

They get generated when they are needed (via method_missing). Why do
you care about whether the methods exists rather than just going ahead
and calling them ?

Fred

Because the actual script is something like:

association_through_item.methods(true).each do |method|   #No method position here!

  association_through_item.send(association_method).meta_eval do

    define_method method do       association_through_item.send(method)     end   end end

So position never gets called because it's not in methods()

Because the actual script is something like:

association_through_item.methods(true).each do |method| #No method position here!

association_through_item.send(association_method).meta_eval do

   define_method method do      association_through_item.send(method)    end end end

So position never gets called because it's not in methods()

You could try calling PlayListItem.define_attribute_methods

Fred

Thanks Fred! Worked like a charm.