aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-05-14 12:48:37 -0500
committerJoshua Peek <josh@joshpeek.com>2008-05-14 12:48:37 -0500
commit49846f85864f4b59d5593c30ee3c59b584d2975d (patch)
tree7f746da60755000b4281ce2b2969508c116c7d3b /activesupport/lib
parent7708650f73ddb4db300ea2059c60c1d907a4384e (diff)
downloadrails-49846f85864f4b59d5593c30ee3c59b584d2975d.tar.gz
rails-49846f85864f4b59d5593c30ee3c59b584d2975d.tar.bz2
rails-49846f85864f4b59d5593c30ee3c59b584d2975d.zip
Create a seperate file for ActiveSupport::OrderedHash.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support.rb1
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb43
-rw-r--r--activesupport/lib/active_support/ordered_options.rb44
3 files changed, 44 insertions, 44 deletions
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index 4d2f873a8d..e4cb145c98 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -39,6 +39,7 @@ require 'active_support/cache'
require 'active_support/dependencies'
require 'active_support/deprecation'
+require 'active_support/ordered_hash'
require 'active_support/ordered_options'
require 'active_support/option_merger'
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
new file mode 100644
index 0000000000..6993621ef9
--- /dev/null
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -0,0 +1,43 @@
+# OrderedHash is namespaced to prevent conflicts with other implementations
+module ActiveSupport
+ # Hash is ordered in Ruby 1.9!
+ if RUBY_VERSION >= '1.9'
+ OrderedHash = ::Hash
+ else
+ class OrderedHash < Array #:nodoc:
+ def []=(key, value)
+ if pair = assoc(key)
+ pair.pop
+ pair << value
+ else
+ self << [key, value]
+ end
+ end
+
+ def [](key)
+ pair = assoc(key)
+ pair ? pair.last : nil
+ end
+
+ def delete(key)
+ pair = assoc(key)
+ pair ? array_index = index(pair) : nil
+ array_index ? delete_at(array_index).last : nil
+ end
+
+ def keys
+ collect { |key, value| key }
+ end
+
+ def values
+ collect { |key, value| value }
+ end
+
+ def to_hash
+ returning({}) do |hash|
+ each { |array| hash[array[0]] = array[1] }
+ end
+ end
+ end
+ end
+end
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index 3172f62f0d..306376e9ae 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -1,47 +1,3 @@
-# OrderedHash is namespaced to prevent conflicts with other implementations
-module ActiveSupport
- # Hash is ordered in Ruby 1.9!
- if RUBY_VERSION >= '1.9'
- OrderedHash = ::Hash
- else
- class OrderedHash < Array #:nodoc:
- def []=(key, value)
- if pair = assoc(key)
- pair.pop
- pair << value
- else
- self << [key, value]
- end
- end
-
- def [](key)
- pair = assoc(key)
- pair ? pair.last : nil
- end
-
- def delete(key)
- pair = assoc(key)
- pair ? array_index = index(pair) : nil
- array_index ? delete_at(array_index).last : nil
- end
-
- def keys
- collect { |key, value| key }
- end
-
- def values
- collect { |key, value| value }
- end
-
- def to_hash
- returning({}) do |hash|
- each { |array| hash[array[0]] = array[1] }
- end
- end
- end
- end
-end
-
class OrderedOptions < ActiveSupport::OrderedHash #:nodoc:
def []=(key, value)
super(key.to_sym, value)