Classes like activerecord, etc contains strange elements like
‘belongs_to :something’, ‘has_many :smth’ etc… what is it? I can’t find
them in ruby lang documentation… it’s similar to ‘attr_accessor’ and
other costructions, how I can create my own constructions and how I must
understand them? Could anyone give me some links where I can read about
it?
zven wrote:
Classes like activerecord, etc contains strange elements like
‘belongs_to :something’, ‘has_many :smth’ etc… what is it? I can’t find
them in ruby lang documentation… it’s similar to ‘attr_accessor’ and
other costructions, how I can create my own constructions and how I must
understand them? Could anyone give me some links where I can read about
it?
http://api.rubyonrails.org - just look in the list of methods.
David Black’s Ruby for Rails has a lot of material that would be
helpful to understanding how these methods work. And Jamis B. just
wrote an article on DSL’s that might be helpful:
http://jamis.jamisbuck.org/articles/2006/04/20/writing-domain-specific-languages
–
Josh S.
http://blog.hasmanythrough.com
On Fri, 2006-04-21 at 07:07 -0500, zven wrote:
Classes like activerecord, etc contains strange elements like
‘belongs_to :something’, ‘has_many :smth’ etc… what is it? I can’t find
them in ruby lang documentation… it’s similar to ‘attr_accessor’ and
other costructions, how I can create my own constructions and how I must
understand them? Could anyone give me some links where I can read about
it?
Oh, sorry At this night I forget class methods
On 4/21/06, zven [email protected] wrote:
Classes like activerecord, etc contains strange elements like
‘belongs_to :something’, ‘has_many :smth’ etc… what is it? I can’t find
them in ruby lang documentation… it’s similar to ‘attr_accessor’ and
other costructions, how I can create my own constructions and how I must
understand them? Could anyone give me some links where I can read about
it?
These belong to Rails, not to the Ruby standard library.
However, they are simply class methods of ActiveRecord.
You can easily define your own (though the Rails association methods
are very sophisticated.)
class Blah
example() is a class method of Blah.
Like all classes, Blah is an instance of Class.
def self.example(message)
puts message
end
end
class Something < Blah
Method calls inside the body of the class definition are called
when the class is parsed by Ruby.
example “see?”
end
If you paste the above into irb, you’ll see:
see?
printed to STDOUT.
If you want to know more, check out the book ‘Ruby for Rails’ by David
A. Black.
–Wilson.