ruby-on-railsrubydynamic-method

Ruby equivalents for PHP's magic methods __call, __get and __set


I am pretty sure that Ruby has these (equivalents for __call, __get and __set), because otherwise how find_by would work in Rails? Maybe someone could give a quick example of how to define methods that act same as find_by?

Thanks


Solution

  • The dynamic finders are done by implementing method missing

    http://ruby-doc.org/core/classes/Kernel.html#M005925

    Take a look at this blog post, it will give you the gist of how they work..

    http://blog.hasmanythrough.com/2006/8/13/how-dynamic-finders-work