Prev | Current Page 515 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


Public Instance Methods
human_name()
Return the human readable version of the column name as follows:
Column.new("first_name", nil, "varchar(255)").human_name #=> "First name"
klass()
klass returns the Ruby class that corresponds to the abstract data type of the column. For
example, if the SQL column is of type :integer, the class returned from this method is Fixnum.
Table A-1 lists the abstract data types for columns and the corresponding classes that this
method will return.
Table A-1: Abstract Data Types and Corresponding Classes
Type Class
:integer Fixnum
:float Float
:decimal BigDecimal
:datetime Time
:date Date
:timestamp Time
:time Time
:text String
:string String
:binary String
:boolean Object
number?()
number? returns true if the data type of this Column is a float, integer, or decimal.
APPENDIX ?–  ACTIVE RECORD METHODS IN DETAIL 237
text?()
text? returns true if the data type of this Column is string or text.
type_cast(value)
type_cast casts the given column value to an appropriate instance.


Pages:
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527