Created
June 14, 2010 00:55
-
-
Save lsegal/437136 to your computer and use it in GitHub Desktop.
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
# Array#flatten seems to call #to_ary on all elements of the array, regardless | |
# of whether they are Arrays and without checking if the object has a to_ary first. | |
# | |
# More peculiarly, calling "super" inside of method_missing does not return from | |
# the call to the method_missing method, instead it jumps completely out of | |
# the call without performing any actions after "super" is called. | |
# | |
# Note that Foo.new.respond_to?(:to_ary) == false, so method_missing should raise an | |
# exception, though it does not. | |
class Foo | |
def method_missing(meth, *args, &block) | |
puts "calling method: #{meth}" | |
p super | |
puts "AFTER SUPER" | |
end | |
end | |
[Foo.new].flatten | |
puts "END" | |
# Expected (assuming super does not raise exception, though it should): | |
# | |
# calling method: to_ary | |
# <<some value, nil maybe>> | |
# AFTER SUPER | |
# END | |
# | |
# Actual: | |
# | |
# calling method: to_ary | |
# END | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment