Posted By

Shamaoke on 03/09/11


Tagged

ruby definemethod metaprogramming


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

WaxWing


Defining the instance and class methods using define_method


 / Published in: Ruby
 

  1. class Example
  2. class << self
  3. define_method(:one) { puts 'one' }
  4. define_method(:two) { puts 'two' }
  5. end
  6.  
  7. define_method(:three) { puts 'three' }
  8. define_method(:four) { puts 'four' }
  9. end
  10.  
  11. Example.one #=> one
  12. Example.two #=> two
  13.  
  14. Example.new.three #=> three
  15. Example.new.four #=> four

Report this snippet  

You need to login to post a comment.