Hi, At what point in rails are the methods for a models attributes defined? Because I have the following code: http://pastie.caboo.se/140435 And it returns in irb:>> s = Playlist.find(:first).songs >> false >> 1If I do this in irb: (The PlaylistItem model has an attribute ''position''>> s = Playlist.find(:first).playlist_items[0].methods(true).include?(''position'') >> trueHow''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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 18 Jan 2008, at 09:56, Leon Bogaert wrote:> > Hi, > > At what point in rails are the methods for a models attributes > defined? > > Because I have the following code: > http://pastie.caboo.se/140435> 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> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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() -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 18 Jan 2008, at 10:30, Leon Bogaert wrote:> > 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> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Fred! Worked like a charm. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---