Hi, this blog is no longer maintained, my new blog is here

Ruby On Rails and a Conning Israeli entrepreneur

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  

0 comments:


The Web Ask eizesus.com

Subscribe

    follow me on Twitter

    Twiters Around

    About Me

    My photo
    I am a web developer for more than 9 years, managed, cried, coded, designed and made money in this industry. now trying to do it again.

    Labels