Skip to content

Instantly share code, notes, and snippets.

@julik
Created August 28, 2010 12:14
Show Gist options
  • Save julik/555071 to your computer and use it in GitHub Desktop.
Save julik/555071 to your computer and use it in GitHub Desktop.
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