aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-08-06 13:11:44 +0200
committerXavier Noria <fxn@hashref.com>2010-08-06 13:11:44 +0200
commite0a0638094192061b5537f776a6a250b85cb09b8 (patch)
treec2cf6e0546758aed2deb0c2d024d9c0edb77362b /activesupport/lib/active_support
parentcdbc880055fba8bfa63b2c3c5fda94c48f87b037 (diff)
downloadrails-e0a0638094192061b5537f776a6a250b85cb09b8.tar.gz
rails-e0a0638094192061b5537f776a6a250b85cb09b8.tar.bz2
rails-e0a0638094192061b5537f776a6a250b85cb09b8.zip
commit review: say clearly that AS::OrderedHash is about insertion order, be more neutral in wording, do not imply lack of ordering is a problem
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb18
-rw-r--r--activesupport/lib/active_support/ordered_options.rb8
2 files changed, 14 insertions, 12 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index e19d9d7dc1..2e8d538d0b 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -4,15 +4,17 @@ YAML.add_builtin_type("omap") do |type, val|
ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)]
end
-# Hash is not ordered in ruby 1.8.x. What it means is there is no guarantee of order of keys when
-# method Hash#keys in invoked. Similarly Hash#values and Hash#each can't guarantee that each time
-# the output will contain exactly same value in the same order. <tt>OrderedHash</tt> solves that
-# problem.
-#
-# ActiveSupport::OrderedHash[:boy, 'John', :girl, 'Mary']
-#
-# OrderedHash is namespaced to prevent conflicts with other implementations.
module ActiveSupport
+ # The order of iteration over hashes in Ruby 1.8 is undefined. For example, you do not know the
+ # order in which +keys+ will return keys, or +each+ yield pairs. <tt>ActiveSupport::OrderedHash</tt>
+ # implements a hash that preserves insertion order, as in Ruby 1.9:
+ #
+ # oh = ActiveSupport::OrderedHash.new
+ # oh[:a] = 1
+ # oh[:b] = 2
+ # oh.keys # => [:a, :b], this order is guaranteed
+ #
+ # <tt>ActiveSupport::OrderedHash</tt> is namespaced to prevent conflicts with other implementations.
class OrderedHash < ::Hash #:nodoc:
def to_yaml_type
"!tag:yaml.org,2002:omap"
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index b0584072c1..7fc2b45b51 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -5,16 +5,16 @@ require 'active_support/ordered_hash'
# h = ActiveSupport::OrderedOptions.new
# h[:boy] = 'John'
# h[:girl] = 'Mary'
-# h[:boy] #=> 'John'
-# h[:girl] #=> 'Mary'
+# h[:boy] # => 'John'
+# h[:girl] # => 'Mary'
#
# Using <tt>OrderedOptions</tt> above code could be reduced to:
#
# h = ActiveSupport::OrderedOptions.new
# h.boy = 'John'
# h.girl = 'Mary'
-# h.boy #=> 'John'
-# h.girl #=> 'Mary'
+# h.boy # => 'John'
+# h.girl # => 'Mary'
#
module ActiveSupport #:nodoc:
class OrderedOptions < OrderedHash