lib/active_support/multibyte/chars.rb in activesupport-1.4.2 vs lib/active_support/multibyte/chars.rb in activesupport-1.4.3
- old
+ new
@@ -41,11 +41,11 @@
@string
end
# Create a new Chars instance.
def initialize(str)
- @string = (str.string rescue str)
+ @string = str.respond_to?(:string) ? str.string : str
end
# Returns -1, 0 or +1 depending on whether the Chars object is to be sorted before, equal or after the
# object on the right side of the operation. It accepts any object that implements +to_s+. See String.<=>
# for more details.
@@ -68,22 +68,22 @@
# Try to forward all undefined methods to the handler, when a method is not defined on the handler, send it to
# the contained string. Method_missing is also responsible for making the bang! methods destructive.
def method_missing(m, *a, &b)
begin
# Simulate methods with a ! at the end because we can't touch the enclosed string from the handlers.
- if m.to_s =~ /^(.*)\!$/
+ if m.to_s =~ /^(.*)\!$/ && handler.respond_to?($1)
result = handler.send($1, @string, *a, &b)
if result == @string
result = nil
else
@string.replace result
end
- else
+ elsif handler.respond_to?(m)
result = handler.send(m, @string, *a, &b)
+ else
+ result = @string.send(m, *a, &b)
end
- rescue NoMethodError
- result = @string.send(m, *a, &b)
rescue Handlers::EncodingError
@string.replace handler.tidy_bytes(@string)
retry
end
@@ -124,6 +124,6 @@
require 'utf8proc_native'
require 'active_support/multibyte/handlers/utf8_handler_proc'
ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8HandlerProc
rescue LoadError
ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8Handler
-end
\ No newline at end of file
+end