Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enclosing_method(var1,var2) do
- enclosing_method(var3,var4) do
- get_tree # This method should return an array of it's enclosing methods
- # e.g. [get_tree, enclosing_method, enclosing_method, main]
- end
- end
- class Myclass
- @@all_instances
- def initialize
- @parents = get_tree # method that will return
- # all of the containing instances / anythings
- @content = yield
- @@all_instances << self
- end
- attr_reader :content
- attr_reader :parents
- end
- Myclass.new do
- Myclass.new do
- get_tree # => [Myclass, Myclass, <main>]
- end
- end
- > Myclass.all_instances[0].parents # => [<main>]
- > Myclass.all_instances[1].parents # => [Myclass, <main>]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement