Prev | Current Page 91 | Next

Brad Ediger

"Advanced Rails"

whiny_
nils to false.
Core Extensions
The Core Extensions are ActiveSupport??™s collection of extensions to Ruby??™s core
classes and modules. They are basic design patterns solving problems that are
encountered often in Ruby. These methods are one level below the Rails API; they
are the internal functions that Rails uses. However, we describe them here because
Array
Array | 61
they are extremely useful during the process of building a Rails application. The core
extensions are low-level utility methods for Ruby; they do not make the impossible
possible, but they do help to simplify application code.
Array
Conversions core_ext/array/conversions.rb
??? Array#to_sentence joins the array??™s elements and converts to a string:
%w(Larry Curly Moe).to_sentence # => "Larry, Curly, and Moe"
??? Array#to_s(:db) collects an array of ActiveRecord objects (or other objects that
respond to the id method) into a SQL-friendly string.
??? Array#to_xml converts an array of ActiveRecord objects into XML. This is usually used
to implement REST-style web services. It relies on the contained objects??™ implementation
of to_xml (such as ActiveRecord::XmlSerialization.to_xml).
render :xml => Product.find(:all).to_xml
Note that render(:xml => ...) and render(:json => ...) are new synonyms for
render(:text => ...) that change the response??™s MIME type appropriately.
Grouping core_ext/array/grouping.


Pages:
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103