BACKTRACE

(condense)

Back to Posts List

GET

Dynamically adding methods

This is divine, ruby is too great to be true. no explanation needed.


  1. class Object  
  2.   def def(method_name, &block)  
  3.     (class << selfself end).send(:define_method, method_name, block)  
  4.   end  
  5. end  
  6.   
  7. x = Object.new  
  8.   
  9. string = “This is a test”  
  10. x.def(:elad_says) {puts “Elad says: ” + string}  
  11.   
  12. x.elad_says  

POST

blog comments powered by Disqus

I Don't have cookies.

ELAD ENV

Variable Value
LINKEDIN
TWITTER
FACEBOOK
GITHUB
WWR
IRC
{ 'irc.freenode.net' => [ '#rubyonrails', '#railsbridge', '#ruby', '#mootools' ]}
SKYPE
eladmeidar

You're seeing this error because I think it is funny.