Skip to content

Instantly share code, notes, and snippets.

@ushis
Created January 29, 2013 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ushis/4668824 to your computer and use it in GitHub Desktop.
Save ushis/4668824 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
puts "ruby #{RUBY_VERSION}"
class A
def a
if respond_to?(:b)
puts "I am responding to b."
else
puts "I am not responding to b."
end
begin
b
rescue NoMethodError
puts "I can not call b."
end
end
end
class B < A
protected
def b
puts "I can call b."
end
end
B.new.a
# ruby 2.0.0
# I am not responding to b.
# I can call b.
#
# ruby 1.9.3
# I am responding to b.
# I can call b.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment