vendor/rails/activesupport/lib/active_support/multibyte/chars.rb in radiant-0.6.9 vs vendor/rails/activesupport/lib/active_support/multibyte/chars.rb in radiant-0.7.0
- old
+ new
@@ -8,11 +8,11 @@
# encoding safe manner. All the normal String methods are also implemented on the proxy.
#
# String methods are proxied through the Chars object, and can be accessed through the +chars+ method. Methods
# which would normally return a String object now return a Chars object so methods can be chained.
#
- # "The Perfect String ".chars.downcase.strip.normalize #=> "the perfect string"
+ # "The Perfect String ".chars.downcase.strip.normalize # => "the perfect string"
#
# Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made.
# If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them.
#
# bad.explicit_checking_method "T".chars.downcase.to_s
@@ -38,17 +38,19 @@
def to_str
# Using any other ways of overriding the String itself will lead you all the way from infinite loops to
# core dumps. Don't go there.
@string
end
-
+
# Make duck-typing with String possible
- def respond_to?(method)
- super || @string.respond_to?(method) || handler.respond_to?(method) ||
- (method.to_s =~ /(.*)!/ && handler.respond_to?($1)) || false
+ def respond_to?(method, include_priv = false)
+ super || @string.respond_to?(method, include_priv) ||
+ handler.respond_to?(method, include_priv) ||
+ (method.to_s =~ /(.*)!/ && handler.respond_to?($1, include_priv)) ||
+ false
end
-
+
# Create a new Chars instance.
def initialize(str)
@string = str.respond_to?(:string) ? str.string : str
end
@@ -117,17 +119,11 @@
private
# +utf8_pragma+ checks if it can send this string to the handlers. It makes sure @string isn't nil and $KCODE is
# set to 'UTF8'.
- if RUBY_VERSION < '1.9'
- def utf8_pragma?
- !@string.nil? && ($KCODE == 'UTF8')
- end
- else
- def utf8_pragma?
- !@string.nil? && (Encoding.default_external == Encoding::UTF_8)
- end
+ def utf8_pragma?
+ !@string.nil? && ($KCODE == 'UTF8')
end
end
end
# When we can load the utf8proc library, override normalization with the faster methods