Created
October 29, 2011 15:00
-
-
Save devboy/1324556 to your computer and use it in GitHub Desktop.
Mixins on instances
This file contains hidden or 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
class MyObject | |
def instanceMethod | |
"MyObject" | |
end | |
end | |
module MyMixin | |
def instanceMethod | |
"MyMixin" | |
end | |
def mixinMethod | |
end | |
end | |
a = MyObject.new | |
b = MyObject.new | |
b.extend MyMixin | |
puts b.respond_to? :mixinMethod # => true | |
puts a.respond_to? :mixinMethod # => false | |
puts a.instanceMethod # => MyObject | |
puts b.instanceMethod # => MyMixin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment