Forum: Ruby on Rails Conceptual q about rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
783fed8af50259766b40d2f550ec5974?d=identicon&s=25 zven (Guest)
on 2006-04-21 03:08
(Received via mailing list)
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?
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-04-21 03:19
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 Buck just
wrote an article on DSL's that might be helpful:
http://jamis.jamisbuck.org/articles/2006/04/20/wri...

--
Josh Susser
http://blog.hasmanythrough.com
783fed8af50259766b40d2f550ec5974?d=identicon&s=25 zven (Guest)
on 2006-04-21 03:20
(Received via mailing list)
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
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-04-21 03:26
(Received via mailing list)
On 4/21/06, zven <zven@nm.ru> 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.
This topic is locked and can not be replied to.