Created
February 15, 2013 23:27
-
-
Save elarkin/4964461 to your computer and use it in GitHub Desktop.
ruby 1.9.* does not respect respond_to? :to_ary when calling flatten
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_config klass | |
var = klass.new | |
unless !var.respond_to?(:to_ary) && [var].flatten == [var] | |
puts "#{klass.name} is misbehaved" | |
end | |
end | |
class RespondToMissingTest | |
def respond_to_missing? method, *rest | |
if method.to_sym == :to_ary | |
false | |
else | |
super | |
end | |
end | |
def method_missing *args | |
args | |
end | |
end | |
class RespondToTest | |
def respond_to? method, *rest | |
if method.to_sym == :to_ary | |
false | |
else | |
super | |
end | |
end | |
def method_missing *args | |
args | |
end | |
end | |
class MethodButNonResponsiveTest | |
def to_ary | |
raise NoMethodError | |
end | |
def respond_to? method, *rest | |
if method.to_sym == :to_ary | |
false | |
else | |
super | |
end | |
end | |
end | |
test_config RespondToMissingTest | |
test_config RespondToTest | |
test_config MethodButNonResponsiveTest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment