I got this sample code from datamapper http://datamapper.org/getting-started.html
class Post
include DataMapper::Resource
property :id, Serial # An auto-increment integer key
property :title, String # A varchar type string, for short strings
property :body, Text # A text block, for longer string data.
property :created_at, DateTime # A DateTime, for any date you might like.
end
Can anyone tell me that how "property" generate? Is it a function, variable, class variable or instance variable or a constant?
sometime i also saw this kind of code
class CarModel
attribute :name
attribute :hello
end
but no idea how does this generate
propertyis a method, as isattribute. Both are being called/invoked within the class definition. What they "do" is a separate question.property :id, Serialis just call of function with 2 arguments. It changes class (adds property). It's meta-programming tip. Ruby has a lot of it.