Skip to content

Instantly share code, notes, and snippets.

@elarkin
Created February 15, 2013 23:27
Show Gist options
  • Save elarkin/4964461 to your computer and use it in GitHub Desktop.
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
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