Skip to content

Instantly share code, notes, and snippets.

@devboy
Created October 29, 2011 15:00
Show Gist options
  • Save devboy/1324556 to your computer and use it in GitHub Desktop.
Save devboy/1324556 to your computer and use it in GitHub Desktop.
Mixins on instances
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