Permalink
Browse files

Use respond_to_missing? for Chars

  • Loading branch information...
1 parent 3ea70f9 commit 9bda37474e2cd3db63102f6b63246ebc54011ad2 @marcandre marcandre committed May 5, 2012
Showing with 11 additions and 2 deletions.
  1. +2 −2 activesupport/lib/active_support/multibyte/chars.rb
  2. +9 −0 activesupport/test/multibyte_chars_test.rb
@@ -62,8 +62,8 @@ def method_missing(method, *args, &block)
# Returns +true+ if _obj_ responds to the given method. Private methods are included in the search
# only if the optional second parameter evaluates to +true+.
- def respond_to?(method, include_private=false)
- super || @wrapped_string.respond_to?(method, include_private)
+ def respond_to_missing?(method, include_private)
+ @wrapped_string.respond_to?(method, include_private)
end
# Returns +true+ when the proxy class can handle the string. Returns +false+ otherwise.
@@ -458,6 +458,15 @@ def test_respond_to_knows_which_methods_the_proxy_responds_to
assert !''.mb_chars.respond_to?(:undefined_method) # Not defined
end
+ def test_method_works_for_proxyed_methods
+ assert_equal 'll', 'hello'.mb_chars.method(:slice).call(2..3) # Defined on Chars
+ chars = 'hello'.mb_chars
+ assert_equal 'Hello', chars.method(:capitalize!).call # Defined on Chars
+ assert_equal 'Hello', chars
+ assert_equal 'jello', 'hello'.mb_chars.method(:gsub).call(/h/, 'j') # Defined on String
+ assert_raise(NameError){ ''.mb_chars.method(:undefined_method) } # Not defined
+ end
+
def test_acts_like_string
assert 'Bambi'.mb_chars.acts_like_string?
end

0 comments on commit 9bda374

Please sign in to comment.