Skip to content

Instantly share code, notes, and snippets.

@alindeman
Created December 2, 2012 20:47
Show Gist options
  • Save alindeman/4190985 to your computer and use it in GitHub Desktop.
Save alindeman/4190985 to your computer and use it in GitHub Desktop.
class Foo
def bar
"wtf?"
end
protected :bar
def invoke_bar
public_send(:bar)
end
end
puts Foo.public_send(:bar) rescue puts "error; this seems normal"
puts Foo.new.invoke_bar
# The last statement outputs "wtf?" on:
# * 1.9.3p194
# * 1.9.3p327
# The last statement raises a NoMethodError on:
# * JRuby 1.7.0
# * rubinius 2.0.0dev 2279857e
#
# I /expected/ the NoMethodError behavior
@myronmarston
Copy link

Shouldn't line 12 be Foo.new.public_send(:bar)? You haven't defined a class method bar.

@peterc
Copy link

peterc commented Dec 3, 2012

+1 to myron, though it does work as you'd expect even if you do that (NoMethodError exception).

BTW, this was a bug in Rubinius until several months ago too: jfirebaugh/rubinius@b3a4533

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment