Posted By

inkdeep on 03/10/10


Tagged

ruby introspection interrogation caller


Versions (?)

Ruby caller experiments


 / Published in: Ruby
 

  1. class Kung
  2. mstr = %-
  3. def foo
  4. puts 'Hello World from Kung.foo'
  5. puts caller(0).inspect
  6. end
  7. -
  8. module_eval mstr
  9. end
  10.  
  11. Kung.new.foo
  12.  
  13.  
  14.  
  15. class Monkey
  16. line, mstr = __LINE__, %-
  17. def see
  18. puts 'Hello World from Monkey.see'
  19. puts caller(0)
  20. end
  21. -
  22. module_eval mstr, __FILE__, line
  23. end
  24.  
  25. Monkey.new.see
  26.  
  27.  
  28. class Monkey
  29. module_eval(<<-EOS, __FILE__, __LINE__)
  30. def see
  31. puts 'Hello World from Monkey.see'
  32. puts caller(0)
  33. end
  34. EOS
  35. end
  36.  
  37. Monkey.new.see

Report this snippet  

You need to login to post a comment.