Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
Created August 6, 2012 13:35
Show Gist options
  • Save stevenbristol/3274502 to your computer and use it in GitHub Desktop.
Save stevenbristol/3274502 to your computer and use it in GitHub Desktop.
include and extend using included
module Log
def Log.included cls
cls.extend Log #also works by passing self, but Log is less confusing
end
def log str
p str
end
end
class Thing
include Log
log "works from class" # => "works from class"
def test_log
log "works from instance"
self.log "works from self (in instance)"
Thing.log "works from class (in instance)"
end
end
Thing.new.test_log # => "works from instance"
# => "works from self (in instance)"
# => "works from class (in instance)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment