plugins - Ruby Base.send calling it like instance method in model when using include and extend -
ruby library code
module yaffle module actsasyaffle def self.included(base) base.extend(classmethods) end module classmethods def acts_as_yaffle(options = {}) cattr_accessor :yaffle_text_field self.yaffle_text_field = (options[:yaffle_text_field] || :last_squawk).to_s include yaffle::actsasyaffle::localinstancemethods end end ... more code ... end end activerecord::base.send(:include, activerecord::acts::taggable) why when phone call acts_as_yaffle in model, beingness used
class hickwall < activerecord::base acts_as_yaffle end does activerecord::base.send(:include,...) included classmethods instance eventhough base of operations extended (base.extend(classmethods) ? acts_as_yaffle declared classmethods.
it is class method. consider example:
class c def my_instance_method puts 'hello instance' end def self.my_class_method puts 'hello class' end my_instance_method # nomethoderror my_class_method # hello class end inside class c ... end can phone call class methods, because there no instance send method phone call to. library code written using mutual pattern set class methods within module. improve understanding, illustration class wrote above equivalent this:
module m def my_instance_method puts 'hello instance' end def self.included(base) base.extend(classmethods) end module classmethods def my_class_method puts 'hello class' end end end ruby plugins include extend
No comments:
Post a Comment