Hallo – I’m trying to decorate the default behaviour of
ActiveRecord::Base#method_missing() with the following code:
alias_method( :b023_method_missing, :method_missing )
unless method_defined?( :b023_method_missing )
def method_missing( method, args )
puts "\n**** – In method_missing()"
b023_method_missing( method, args )
This, to my thinking, should simply do what ActiveRecord normally does
with calls to the attributes like “model.name”, etc.
However, what is happening is that I am getting a “stack level too deep”
When run in the console, I get “***** – In method_missing()” printed a
million times, then the stack overflow error.
It seems to be that the the call to alias_method is happening twice
(despite the unless guard), thus creating an infinite loop.
Has anyone successfully done something like this with ActiveRecord, and
if so, could they please tell me how!