method_missing

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 ?

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

#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.