i''m using method_missing to implement a simple metaprogramming that checks for account rights. in Account << ActiveRecord::Base i defined: def method_missing(m, a = {}) if m.to_s =~ /^has_right_(.*)$/ ... calls another method passing $1 parameter end end it seems to override some of the active record methods based on method missing. in the console it seems to work ok so i got some problem in debugging. how can i call from Account#method_missing the activeRecord::Base#method_missing ? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 March 2010 10:23, eugenio <eugenio.modesti-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i''m using method_missing to implement a simple metaprogramming that > checks for account rights. > > it seems to override some of the active record methods based on method > missing. in the console it seems to work ok so i got some problem in > debugging.This explains part of the problem: http://ruby.tie-rack.org/6/safely-overriding-method_missing-in-a-class-that-already-has-it/ Calling to "super" should be part of your solution... def method_missing(m, *args, &block) if m.to_s =~ /^has_right_(.*)$/ ... calls another method passing $1 parameter else super(m, *args, &block) end end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
#i added this line: alias_method :ar_method_missing, :method_missing #and an else condition in my method_missing def method_missing(m,*a,&block) if m.to_s =~ /^has_right_(.*)$/ ... calls another method passing $1 parameter else ar_method_missing(m,*a, &block) end end it seems to work now. On 18 Mar, 11:23, eugenio <eugenio.mode...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i''m using method_missing to implement a simple metaprogramming that > checks for account rights. > > in Account << ActiveRecord::Base i defined: > > def method_missing(m, a = {}) > if m.to_s =~ /^has_right_(.*)$/ > ... calls another method passing $1 parameter > end > end > > it seems to override some of the active record methods based on method > missing. in the console it seems to work ok so i got some problem in > debugging. > > how can i call from Account#method_missing the > activeRecord::Base#method_missing ?-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Mar 18, 2010 at 12:12 PM, eugenio <eugenio.modesti-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> #i added this line: > alias_method :ar_method_missing, :method_missing > > #and an else condition in my method_missing > > def method_missing(m,*a,&block) > if m.to_s =~ /^has_right_(.*)$/ > ... calls another method passing $1 parameter > else > ar_method_missing(m,*a, &block) > end > end > > it seems to work now.Please don''t do that. This is ordinary object-oriented programming. If you override a method and want to delegate to the parent just call super. That''s what super is for. Aliasing is an inappropriate solution to this. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.