Skip to content

Instantly share code, notes, and snippets.

@code-for-coffee
Created July 22, 2015 05:21
Show Gist options
  • Save code-for-coffee/c8d23ccfacac1fbbd5d1 to your computer and use it in GitHub Desktop.
Save code-for-coffee/c8d23ccfacac1fbbd5d1 to your computer and use it in GitHub Desktop.
mixins with classes
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