The irregular and uncountable rules take care of that
work for us:
"ox".pluralize # => "oxen"
"Ox".pluralize # => "Oxen"
"Octopus".pluralize # => "Octopi"
"Equipment".pluralize # => "Equipment"
Inflector??™s module methods, which actually perform the transformations, are proxied
from the core extensions to String and Integer; they are usually not called directly on the
Inflector module object.* See the respective sections in the Core Extensions documentation
later in the chapter for more information.
JSON json.rb, json/encoders.rb, json/encoders/core.rb
JSON (JavaScript Object Notation, pronounced ???Jason???) is a lightweight subset of Java-
Script??™s notation for literal objects (hash tables) used for data interchange on the Web.
ActiveSupport::JSON provides encoders for most basic Ruby data types. The encoders are
proxied by the Object#to_json method, added by Core Extensions.
(1..5).to_json # => "[1, 2, 3, 4, 5]"
{:a => 1, :b => [2, 3]}.to_json # => "{b: [2, 3], a: 1}"
* "thing".pluralize reads better than Inflector.pluralize("thing").
Whiny Nil
60 | Chapter 2: ActiveSupport and RailTies
The JSON library protects against circular references, which cannot be encoded into JSON:
a = {}
b = {:a => a}
a[:b] = b
a # => {:b=>{:a=>{...}}}
a.to_json
# !> ActiveSupport::JSON::CircularReferenceError: object references itself
Whiny Nil whiny_nil.rb
The extensions to NilClass are an ingenious part of ActiveSupport.
Pages:
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101