Created
August 2, 2012 12:13
-
-
Save stevenbristol/3236612 to your computer and use it in GitHub Desktop.
Using include
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Logger | |
def log str | |
p str | |
end | |
end | |
class Thing1 | |
include Logger | |
begin | |
log "this doesn't work from class" | |
rescue Exception => e | |
p e # => #<NoMethodError: undefined method `log' for Thing1:Class> | |
end | |
def test_log | |
log "this does work from instance" | |
end | |
end | |
Thing1.new.test_log # => "this does work from instance" | |
begin | |
Thing1.log "this doesn't work from class again" | |
rescue Exception => e | |
p e # => #<NoMethodError: undefined method `log' for Thing1:Class> | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment