Remon van Vliet said:
John A. Bailo said:
[...]
This
[the fact that you can easily predict what it actually does]
doesnt apply to the later examples for me though.
I even had trouble with the early examples.
<example>
class Account < ActiveRecord::Base
validates_presence_of :subdomain, :name, :email_address,
assword
validates_uniqueness_of :subdomain
validates_acceptance_of :terms_of_service,
n => :create
validates_confirmation_of
assword, :email_address,
n => :create
end
</example>
Okay, so as a human with an understanding of the semantics of the chosen
names, it looks to me like these validates_foo things describes the account.
The :foo stuff looks like it describes the validate_foo things coming right
before it. For example, "
assword" is what ":validates_confirmation_of"
actually validates the confirmation of. and "
n => :create" is when the
validation occurs (upon creation of the account, is my interpretation).
But then...
<example>
class Project < ActiveRecord::Base
belongs_to
ortfolio
has_one
roject_manager, :class_name => "Person"
has_many :milestones, :dependent => true
has_and_belongs_to_many :categories, :join_table "categorization"
</example>
Does ':class_name => "Person"' modify has_one? Or does it modify
roject_manager? If we're going for consistency, then this says to me that
the "class_name" of "has_one" is "Person". If we're going for common sense,
the programmer probably meant to say that project managers are people.
So is this an error in the code? Or is this correct Ruby code? I have no
idea.
<quote>
You can recognize truth by
its beauty and simplicity.
When you get it right, it is
obvious that it is right.
Richard Feynman, Scientist
</quote>
This wasn't at all obvious to me. What was also amusing to me was that
immediately after that quote, the first example given was:
<example>
Account.transaction(david, mary) do
david.withdrawal(100)
mary.deposit(100)
end
</example>
and this is a textbook example of how NOT to do a bank account transaction
system (threading issues, lack of check for sufficient funds, etc.).
- Oliver