Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
Created August 3, 2012 12:58
Show Gist options
  • Save stevenbristol/3247483 to your computer and use it in GitHub Desktop.
Save stevenbristol/3247483 to your computer and use it in GitHub Desktop.
what is self?
module Logger
def log str
p str
end
end
class Thing
extend Logger
def test_log
begin
self.log "does not work"
rescue Exception => e
p e
end
Thing.log "this does work"
end
def who_am_i
p "self is #{self}"
p "Thing is #{Thing}"
end
end
Thing.new.test_log # => #<NoMethodError: undefined method `log' for #<Thing:0x007fb0fb039db0>>
# => "this does work"
Thing.new.who_am_i # => "self is #<Thing:0x007fb0fb038ac8>"
# => "Thing is Thing"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment