Created
August 28, 2010 12:14
-
-
Save julik/555071 to your computer and use it in GitHub Desktop.
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 Foo | |
attr_reader :opt | |
def initialize(opt) | |
@opt = opt | |
end | |
def meth_in_bar | |
:from_foo | |
end | |
end | |
module Bar | |
def meth_in_bar | |
:from_bar | |
end | |
end | |
a, b, c = Foo.new("Module into object via extend"), Foo.new("Module into object via eigenclass"), Foo.new("Vanilla foo") | |
a.extend(Bar) | |
class << b | |
include Bar | |
end | |
[a, b,c].map{|e| puts "#{e.opt} - #{e.meth_in_bar}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment