This is divine, ruby is too great to be true. no explanation needed.
- class Object
- def def(method_name, &block)
- (class << self; self end).send(:define_method, method_name, block)
- end
- end
- x = Object.new
- string = "This is a test"
- x.def(:elad_says) {puts "Elad says: " + string}
- x.elad_says
0 comments:
Post a Comment