aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-30 07:14:37 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-30 07:14:37 +0000
commitd994b41a05d650cffe441de04754cfbe8fc79c9a (patch)
treebdd580112fdf318dd2e238409e5899aadb2d8cbe
parent28329ec8f8e9ff24f547eb5684634ab81b7e7123 (diff)
downloadrails-d994b41a05d650cffe441de04754cfbe8fc79c9a.tar.gz
rails-d994b41a05d650cffe441de04754cfbe8fc79c9a.tar.bz2
rails-d994b41a05d650cffe441de04754cfbe8fc79c9a.zip
Added method access to OrdredOptions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2422 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activesupport/lib/active_support/ordered_options.rb8
-rw-r--r--activesupport/test/ordered_options_test.rb18
2 files changed, 26 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index 3952ba41f2..5cd7fdadd7 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -15,6 +15,14 @@ class OrderedOptions < Array
pair ? pair.last : nil
end
+ def method_missing(name, *args)
+ if name.to_s =~ /(.*)=$/
+ self[$1.to_sym] = args.first
+ else
+ self[name]
+ end
+ end
+
private
def find_pair(key)
self.each { |i| return i if i.first == key }
diff --git a/activesupport/test/ordered_options_test.rb b/activesupport/test/ordered_options_test.rb
index 83a3e2e561..0247331c6a 100644
--- a/activesupport/test/ordered_options_test.rb
+++ b/activesupport/test/ordered_options_test.rb
@@ -34,4 +34,22 @@ class OrderedOptionsTest < Test::Unit::TestCase
assert_equal test[index].last, value
end
end
+
+ def test_method_access
+ a = OrderedOptions.new
+
+ assert_nil a.not_set
+
+ a.allow_concurreny = true
+ assert_equal 1, a.size
+ assert a.allow_concurreny
+
+ a.allow_concurreny = false
+ assert_equal 1, a.size
+ assert !a.allow_concurreny
+
+ a.else_where = 56
+ assert_equal 2, a.size
+ assert_equal 56, a.else_where
+ end
end