Metaprogramming ActiveRecord Rails

Posted by Dimitar Vouldjeff on Stack Overflow See other posts from Stack Overflow or by Dimitar Vouldjeff
Published on 2010-06-16T21:40:19Z Indexed on 2010/06/16 21:42 UTC
Read the original article Hit count: 233

Hi, I have the following code in my project`s lib directory

module Pasta  
  module ClassMethods
    def self.has_coordinates
      self.send :include, InstanceMethods     
    end
  end

  module InstanceMethods
    def coordinates
      [longitude ||= 43.0, latitude ||= 25.0]
    end
  end   

  ActiveRecord::Base.extend ClassMethods
end

And it should create a class method for ActiveRecord::Base - has_coordinates - which I can "assign" to models... But I receive the error undefined local variable or method 'has_coordinates'

Thanks in advance!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about metaprogramming