Created
July 22, 2015 05:21
-
-
Save code-for-coffee/c8d23ccfacac1fbbd5d1 to your computer and use it in GitHub Desktop.
mixins with classes
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 Testing | |
def about_self? | |
"(\##{self.object_id}): #{self.to_s}" | |
end | |
end | |
class Foo | |
include Testing | |
def initialize | |
@word = 'foo' | |
end | |
def to_s | |
"I am a simple Foo class. Nothing more, nothing less." | |
end | |
end | |
class Bar | |
include Testing | |
def initialize | |
@word = 'bar' | |
end | |
def to_s | |
"I am a simple Bar class. Combined with a Foo class, we create Foo Bar." | |
end | |
end | |
foo = Foo.new | |
bar = Bar.new | |
foo.about_self? | |
bar.about_self? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment