Prev | Current Page 474 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

com
(Chad Pytel), or jyurek@thoughtbot.com (Jon Yurek) with your comments and questions. We??™ll
do our best to help you out, and we??™ll keep detailed notes, so we can improve later versions of
this book!
CHAPTER 8 ?–  ACTIVE RECORD AND THE REAL WORLD 214
Active Record Methods in Detail
ActiveRecord::Base
Public Class Methods
==(object_to_compare)
This method returns true if the object_to_compare is the same as the receiving object or is of
the same Active Record class and has the same ID.
[](attribute_name)
This method returns the value of the specified attribute after it has been typecast and is an
alias for the protected read_attribute method of an Active Record class. While a common
method of accessing the attributes of an Active Record class is via a method call, like
account.first_name, Active Record overrides the [] operator to make each of the attributes
available as a hash parameter on the Active Record class. For example, you can also use the
form account[:first_name].
[]==(attribute_name, new_value)
This method is an alias for the protected write_attribute method of an Active Record class,
and it allows you to set attribute values using a hash-like syntax, for example:
account[:last_name] = "Pytel"
abstract_class?()
abstract_class? returns true if the specified Active Record class is a base Active Record class
and false if it is not.


Pages:
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486