Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
Created August 8, 2012 12:45
Show Gist options
  • Save stevenbristol/3294839 to your computer and use it in GitHub Desktop.
Save stevenbristol/3294839 to your computer and use it in GitHub Desktop.
What is self?
class Thing
def self.log str
p str
end
def test_log
begin
self.log "does not work"
rescue Exception => e
p e
end
Thing.log "this does work A"
end
self.log "this works B" # => "this works B"
log "this works C" # => "this works C"
end
Thing.new.test_log # => #<NoMethodError: undefined method `log' for #<Thing:0x007fb0fb039db0>>
# => "this does work"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment