# Conceptual q about rails

**URL:** <https://www.ruby-forum.com/t/conceptual-q-about-rails/94112>\
**Category:** Rails\
**Created:** [April 21, 2006, 3:08am UTC](https://www.ruby-forum.com/t/conceptual-q-about-rails/94112 "2006-04-21T03:08:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/77aa72/32.png) [@zven](https://www.ruby-forum.com/u/zven)\
**Post date:** [April 21, 2006, 3:08am UTC](https://www.ruby-forum.com/t/conceptual-q-about-rails/94112/1 "2006-04-21T03:08:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![zven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/77aa72/32.png) [@zven](https://www.ruby-forum.com/u/zven)\
**Post date:** [April 21, 2006, 3:19am UTC](https://www.ruby-forum.com/t/conceptual-q-about-rails/94112/2 "2006-04-21T03:19:45Z")

</div>

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](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](http://jamis.jamisbuck.org/articles/2006/04/20/writing-domain-specific-languages)

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![zven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/77aa72/32.png) [@zven](https://www.ruby-forum.com/u/zven)\
**Post date:** [April 21, 2006, 3:20am UTC](https://www.ruby-forum.com/t/conceptual-q-about-rails/94112/3 "2006-04-21T03:20:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/77aa72/32.png) [@zven](https://www.ruby-forum.com/u/zven)\
**Post date:** [April 21, 2006, 3:26am UTC](https://www.ruby-forum.com/t/conceptual-q-about-rails/94112/4 "2006-04-21T03:26:23Z")

</div>

On 4/21/06, zven [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
