Pluralization

I´m aware that Pluralization can be turned-off, but I was wondering why
it was created … just a convention? wouldn´t it be easier if we
followed a convention like models and tables in singular, but models
with initial capped? ex: Person(class)/person(table)? … just curious

Hi, I would say that it’s a rule that your model names are singlular
and your table names are plural within rails. If you follow the rule
set forth, then life is made easier. Also, it was design to be
English like if you read the model’s associations.

Next, we don’t explicity reference the tables names within the models
but we setup associations to other models using the proper syntax.

Finally, you’re free to use non-standard table names as well as turn
off pluralization within rails.

Good luck,

-Conrad

Ken A. wrote:

I’m aware that Pluralization can be turned-off, but I was wondering why
it
was created … just a convention? wouldn´t it be easier if we followed
a
convention like models and tables in singular, but models with initial
capped? ex: Person(class)/person(table)? … just curious

Firstly, Ruby requires constants, like class names, to begin with a
capital
letter, and other things not to.

Next, the best way to write a program is for a human to read. Any fool
can
write a program that a computer can read. Communicating with other
humans is
a major problem in all computing.

So consider the SQL statement CREATE TABLE users. Without regards to
Rails,
should that say ‘user’ or ‘users’? There are many users in the table.
But
you might write SELECT users.name, which looks odd (and not possessive).

So Rails splits this difference by attempting to match the plurality of
a
table name to its local context. User.find(:all) finds all users.
belongs_to
:user links your table’s items to one user in the users table.
has_and_belongs_to_many :users links your table items to many users in
the
users table. And so on.

The system is not perfect, but it leads one to consider - how literate
could
my own program be? Could I make my program literate, even at the level
of
statements’ grammar?


Phlip
Redirecting... ← NOT a blog!!!

hi Phlip

That´s a good explanation … so we have a more ‘semantic’ code and
that´s good.

David A. Black wrote:

Method names can begin with a capital letter too. (Not a practice I’m
eager to encourage, but it’s possible :slight_smile:

I thought when you call them, foo.Bar(), that’s when the interpretter
trips over them.


Phlip

Hi –

On 3/17/07, Phlip [email protected] wrote:

Ken A. wrote:

I’m aware that Pluralization can be turned-off, but I was wondering why it
was created … just a convention? wouldn´t it be easier if we followed a
convention like models and tables in singular, but models with initial
capped? ex: Person(class)/person(table)? … just curious

Firstly, Ruby requires constants, like class names, to begin with a capital
letter, and other things not to.

Method names can begin with a capital letter too. (Not a practice I’m
eager to encourage, but it’s possible :slight_smile:

David


Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)

On Mar 17, 2007, at 23:32, Ken A. wrote:

I´m aware that Pluralization can be turned-off, but I was wondering why
it was created … just a convention? wouldn´t it be easier if we
followed a convention like models and tables in singular, but models
with initial capped? ex: Person(class)/person(table)? … just curious

http://weblog.rubyonrails.com/2005/08/25/10-reasons-rails-does-
pluralization/

:slight_smile:

Hi –

On 3/18/07, Phlip [email protected] wrote:

David A. Black wrote:

Method names can begin with a capital letter too. (Not a practice I’m
eager to encourage, but it’s possible :slight_smile:

I thought when you call them, foo.Bar(), that’s when the interpretter
trips over them.

No, they work:

$ ruby -e ‘a=“”; def a.X; 1; end; p a.X’
1

David


Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
(See what readers are saying! http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)