Skip to content

Instantly share code, notes, and snippets.

@murdoch
Forked from rewinfrey/gist:4611225
Created May 10, 2013 19:34
Show Gist options
  • Save murdoch/5556819 to your computer and use it in GitHub Desktop.
Save murdoch/5556819 to your computer and use it in GitHub Desktop.
class SelfMaker
def yet_what_is_self?
self.class.class_eval do
mirror(self, "Inside class_eval of SelfMaker#yet_what_is_self?")
end
instance_eval do
mirror(self, "Inside instance_eval of SelfMaker#yet_what_is_self?")
end
mirror(self, "Inside SelfMaker#yet_what_is_self?")
end
def mirror(for_self, context)
puts "Where Am I? #{context}"
puts "Who Am I? #{for_self} (My class is: #{for_self.class})"
puts "my object_id: #{for_self.object_id}\n"
end
def self.mirror(for_self, context)
self.new.mirror(for_self, context)
end
end
a_self_is_born = SelfMaker.new
a_self_is_born.yet_what_is_self?
# >> Where Am I? Inside class_eval of SelfMaker#yet_what_is_self?
# >> Who Am I? SelfMaker (My class is: Class)
# >> my object_id: 70352810302640
# >> Where Am I? Inside instance_eval of SelfMaker#yet_what_is_self?
# >> Who Am I? #<SelfMaker:0x007ff89488b8c0> (My class is: SelfMaker)
# >> my object_id: 70352810302560
# >> Where Am I? Inside SelfMaker#yet_what_is_self?
# >> Who Am I? #<SelfMaker:0x007ff89488b8c0> (My class is: SelfMaker)
# >> my object_id: 70352810302560
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment