Skip to content

Instantly share code, notes, and snippets.

@justinwiley
Last active December 21, 2015 23:09
Show Gist options
  • Save justinwiley/6379998 to your computer and use it in GitHub Desktop.
Save justinwiley/6379998 to your computer and use it in GitHub Desktop.
irb(main):020:0* class Foo
irb(main):021:1> def def_methods
irb(main):022:2> method_name = "meth-#{rand(1000)}"
irb(main):023:2> self.class.class_eval do
irb(main):024:3* define_method method_name do
irb(main):025:4* method_name.to_s.capitalize
irb(main):026:4> end
irb(main):027:3> end
irb(main):028:2> end
irb(main):029:1> end
=> nil
irb(main):030:0>
irb(main):031:0* foo=Foo.new
=> #<Foo:0x00000001dabdc0>
irb(main):032:0> foo.def_methods
=> #<Proc:0x00000001d35a30@(irb):24 (lambda)>
irb(main):033:0> foo.methods.grep /meth-/
=> [:"meth-226"]
irb(main):034:0>
irb(main):035:0* foo2=Foo.new
=> #<Foo:0x00000001b0e928>
irb(main):036:0> foo.def_methods
=> #<Proc:0x000000021afbb0@(irb):24 (lambda)>
irb(main):037:0> foo.methods.grep /meth-/
=> [:"meth-226", :"meth-246"]
irb(main):038:0>
irb(main):039:0* foo2.methods.grep /meth-/
=> [:"meth-226", :"meth-246"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment