aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-04-09 19:33:42 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-04-09 19:33:55 -0700
commite77a0311e59048f9f11cfda0ce976a93f4629122 (patch)
tree65613ee2f516d1452f64b7c56ec9d0782dcea449 /activesupport
parentc09744bec9c606593535f42d50487d7d02cab504 (diff)
downloadrails-e77a0311e59048f9f11cfda0ce976a93f4629122.tar.gz
rails-e77a0311e59048f9f11cfda0ce976a93f4629122.tar.bz2
rails-e77a0311e59048f9f11cfda0ce976a93f4629122.zip
Refactor for readability
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb54
1 files changed, 24 insertions, 30 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index 57ead35827..e1a2866863 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -1,13 +1,28 @@
require 'yaml'
+YAML.add_builtin_type("omap") do |type, val|
+ ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)]
+end
+
# OrderedHash is namespaced to prevent conflicts with other implementations
module ActiveSupport
- # Hash is ordered in Ruby 1.9!
- if RUBY_VERSION >= '1.9'
- class OrderedHash < ::Hash #:nodoc:
+ class OrderedHash < ::Hash #:nodoc:
+ def to_yaml_type
+ "!tag:yaml.org,2002:omap"
end
- else
- class OrderedHash < Hash #:nodoc:
+
+ def to_yaml(opts = {})
+ YAML.quick_emit(self, opts) do |out|
+ out.seq(taguri, to_yaml_style) do |seq|
+ each do |k, v|
+ seq.add(k => v)
+ end
+ end
+ end
+ end
+
+ # Hash is ordered in Ruby 1.9!
+ if RUBY_VERSION < '1.9'
def initialize(*args, &block)
super
@keys = []
@@ -55,7 +70,7 @@ module ActiveSupport
end
super
end
-
+
def delete_if
super
sync_keys!
@@ -134,31 +149,10 @@ module ActiveSupport
"#<OrderedHash #{super}>"
end
- private
-
- def sync_keys!
- @keys.delete_if {|k| !has_key?(k)}
- end
- end
- end
-
- class OrderedHash #:nodoc:
- def to_yaml_type
- "!tag:yaml.org,2002:omap"
- end
-
- def to_yaml(opts = {})
- YAML.quick_emit(self, opts) do |out|
- out.seq(taguri, to_yaml_style) do |seq|
- each do |k, v|
- seq.add(k => v)
- end
+ private
+ def sync_keys!
+ @keys.delete_if {|k| !has_key?(k)}
end
- end
end
end
-
- YAML.add_builtin_type("omap") do |type, val|
- ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)]
- end
end