Prev | Current Page 80 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


When Active Record reads the columns of the database table and creates the attribute
mappings, it also reads the data types of those columns and makes sensible mappings among
the attribute types and the database column types, as you might expect. However, the boolean
attribute type is a little different for two reasons. First, a boolean type is not supported in all
databases supported by Active Record. Second, in Ruby only the false constant and the value nil
are considered false. As a workaround, Active Record attribute methods expand the values
considered false to include an empty string, 0, "0", "false", and "f". Conversely, the values
1, "1", "true", and "t" are considered true.
These few assumptions, coupled with the dynamic language features provided by Ruby
(such as duck typing), provide a foundation that makes it possible to provide an incredibly
powerful, yet straightforward, feature set.
?– Note Duck typing is a form of dynamic typing in which the type of an object is not determined strictly by
its class but by its capabilities.


Pages:
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92