On Mar 22, 2006, at 12:29 AM, gwtmp01 / mac.com wrote:
> I was just reading through http://scottraymond.net/articles/ 
> 2006/02/28/rails-1.1, which gives an overview of the next Rails  
> release.
>
> I noticed a number of extensions to the core ruby classes:
>
> 	Object#to_json
> 	Enumerable#group_by
> 	Array#in_groups_of
> 	Hash#to_xml
> 	Array#to_xml
> 	Object#extended_by
>
> and so on.  Earlier versions of Rails also have lots of extensions  
> to the core libraries.

Many of the most useful Rails extensions are actually provided by  
ActiveSupport, which can be installed as a gem and used from non- 
Rails applications.

Most interesting to me, though, is Object#to_json.  This serializes  
basic Ruby types in "JavaScript Object Notation", i.e., as JavaScript  
literals. This is obviously web-specific, but in a web environment,  
it needs to be defined on Object, so that you can serialize any type  
(or get a meaningful error).

This is a nice feature of Ruby: You can add new polymorphic behavior  
to other people's classes, which requires caution, but can be very  
useful in the right circumstances. It's sort of like a single- 
dispatch version of generic functions.

Cheers,
Eric