Created
August 2, 2012 12:18
-
-
Save stevenbristol/3236625 to your computer and use it in GitHub Desktop.
Using extend
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 Thing2 | |
extend Logger | |
log "this does work from class" # => "this does work from class" | |
def test_log | |
begin | |
log "this doesn't work from instance" | |
rescue Exception => e | |
p e | |
end | |
Thing2.log "this does work from class (via class in instance)" | |
end | |
end | |
Thing2.new.test_log # => #<NoMethodError: undefined method `log' for #<Thing2:0x007fcb391016a0>> | |
# => "this does work from class (via class in instance)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment