diff options
author | Daniel Schierbeck <daniel.schierbeck@gmail.com> | 2011-08-29 13:07:03 +0200 |
---|---|---|
committer | Daniel Schierbeck <dasch@zendesk.com> | 2012-04-12 13:47:52 +0200 |
commit | 1bac04e854b42fc0e47162e251105434d356d2b4 (patch) | |
tree | 6efbf7e413dd4dd7346ed4945283efd6d0fb15c8 /activesupport/test | |
parent | 1db54dffaffb83c7a1dacb4db7e4204c7bd1ddba (diff) | |
download | rails-1bac04e854b42fc0e47162e251105434d356d2b4.tar.gz rails-1bac04e854b42fc0e47162e251105434d356d2b4.tar.bz2 rails-1bac04e854b42fc0e47162e251105434d356d2b4.zip |
Optimize the performance of #delegate
Remove the use of #__send__ in order to boost performance. This also
means that you can no longer delegate to private methods on the
target object.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 09ca4e7296..6e1b3ca010 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -60,6 +60,14 @@ Tester = Struct.new(:client) do delegate :name, :to => :client, :prefix => false end +class ParameterSet + delegate :[], :[]=, :to => :@params + + def initialize + @params = {:foo => "bar"} + end +end + class Name delegate :upcase, :to => :@full_name @@ -83,6 +91,17 @@ class ModuleTest < ActiveSupport::TestCase assert_equal "Fred", @david.place.name end + def test_delegation_to_index_get_method + @params = ParameterSet.new + assert_equal "bar", @params[:foo] + end + + def test_delegation_to_index_set_method + @params = ParameterSet.new + @params[:foo] = "baz" + assert_equal "baz", @params[:foo] + end + def test_delegation_down_hierarchy assert_equal "CHICAGO", @david.upcase end |