Kit Ho
Kit Ho

Reputation: 26968

Ruby: What is it declare in a class?

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

Upvotes: 0

Views: 69

Answers (1)

mechanicalfish
mechanicalfish

Reputation: 12826

It is a method that is included when you do:

include DataMapper::Resource

You can see its source code here if you're interested in digging in deeper.

It basically adds a property to the list of properties in your Post resource.

Upvotes: 1

Related Questions