Prev | Current Page 493 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

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 on 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 allows setting of attribute values using a hash-like syntax, for example:
account[:last_name] = "Pytel"
attribute_names()
This method returns an alphabetically sorted array of the names of all the attributes available
on this Active Record class.
attribute_present?(attribute)
attribute_present? returns true if the specified attribute has a value that was either set by
you or loaded from the database. To return true, the value should be neither nil nor return
false to empty?.
attributes(options = nil)
This method returns a hash of all of this object??™s attributes, with the attribute names as keys
and clones of the attribute objects as their values:
Account.


Pages:
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505