Skip to content

Instantly share code, notes, and snippets.

@bquorning

bquorning/flatten.rb

Created Feb 19, 2018
Embed
What would you like to do?
Did Ruby 2.5 introduce a new bug, or fix an old bug? The implicit `flatten` -> `to_ary` -> `respond_to_missing` call has changed.
class A
def respond_to?(method, include_all = false)
::Kernel.puts "respond_to?(#{method.inspect}, #{include_all.inspect})"
end
end
class B
def respond_to_missing?(method, include_all = false)
::Kernel.puts "respond_to_missing?(#{method.inspect}, #{include_all.inspect})"
end
end
puts RUBY_VERSION
[A.new, B.new].flatten
# Output:
#
# 2.4.2
# respond_to?(:to_ary, true)
# respond_to_missing?(:to_ary, false)
#
# 2.5.0
# respond_to?(:to_ary, true)
# respond_to_missing?(:to_ary, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.