Xavier Noria
5/16/2007 9:05:00 PM
On May 16, 2007, at 10:39 PM, Dave Hoefler wrote:
> Robert and Xavier (fxn) -
>
> Thank you for the explanations! That just cleared things up
> tremendously.
>
> So say I have this module (rails plugin):
>
> module Office
> def self.included(base)
> base.extend(ClassMethods)
> end
>
> module ClassMethods
> def working(options={})
> # do something based off the options
> end
> end
>
> end
>
> In one of my models I can then access the method 'working' by:
>
> class ModelName < ActiveRecord::Base
> working :task => "Take a break!"
> end
Exactly.
In regular Ruby you'd need to include Office by hand in the model
class, but in Rails it is normal (I'd say even expected) that the
plugin does the include in AR::Base for you in init.rb using the
idiom mentioned in the previous post.
-- fxn