Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created April 17, 2013 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/5401829 to your computer and use it in GitHub Desktop.
Save myronmarston/5401829 to your computer and use it in GitHub Desktop.
Why does `public_class_method` in an anonymous module make the method public on `Object`?
➜ irb
1.9.3p327 :001 > Object.define_method
NoMethodError: private method `define_method' called for Object:Class
from (irb):1
from /Users/myron/.rvm/rubies/ruby-1.9.3-p327/bin/irb:16:in `<main>'
1.9.3p327 :002 > m = Module.new do
1.9.3p327 :003 > public_class_method :define_method
1.9.3p327 :004?> end
=> #<Module:0x007fd4c493d8e8>
1.9.3p327 :005 > Object.define_method
ArgumentError: wrong number of arguments (0 for 1)
from (irb):5:in `define_method'
from (irb):5
from /Users/myron/.rvm/rubies/ruby-1.9.3-p327/bin/irb:16:in `<main>'
1.9.3p327 :006 > exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment