Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. enclosing_method(var1,var2) do
  2. enclosing_method(var3,var4) do
  3. get_tree # This method should return an array of it's enclosing methods
  4. # e.g. [get_tree, enclosing_method, enclosing_method, main]
  5. end
  6. end
  7.  
  8. class Myclass
  9. @@all_instances
  10. def initialize
  11. @parents = get_tree # method that will return
  12. # all of the containing instances / anythings
  13. @content = yield
  14. @@all_instances << self
  15. end
  16. attr_reader :content
  17. attr_reader :parents
  18. end
  19. Myclass.new do
  20. Myclass.new do
  21. get_tree # => [Myclass, Myclass, <main>]
  22. end
  23. end
  24.  
  25. > Myclass.all_instances[0].parents # => [<main>]
  26. > Myclass.all_instances[1].parents # => [Myclass, <main>]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement