Skip to content

Instantly share code, notes, and snippets.

@cowboyd
Created August 21, 2013 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboyd/6299096 to your computer and use it in GitHub Desktop.
Save cowboyd/6299096 to your computer and use it in GitHub Desktop.
I did not know that.
[1] pry(main)> Class.new.respond_to?(:define_method)
=> false
[2] pry(main)> Module.new.respond_to?(:define_method)
=> false
[3] pry(main)> Class.new.send(:define_method, :yup) {}
=> #<Proc:0x00000100a08cb8@(pry):3 (lambda)>
[4] pry(main)> Module.new.send(:define_method, :yup) {}
=> #<Proc:0x00000100d8f468@(pry):4 (lambda)>
@cowboyd
Copy link
Author

cowboyd commented Aug 21, 2013

As @JEG2 kindly pointed out: https://twitter.com/JEG2/status/370268287675805696

facepalm

For the record, Module#respond_to? takes an optional parameter to include private methods:

[9] pry(main)> Module.new.respond_to?(:define_method, true)
=> true

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