Created
June 20, 2013 06:09
-
-
Save semarco/5820629 to your computer and use it in GitHub Desktop.
experiment with module extend vs delegation
This file contains 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
require 'delegate' | |
class D < SimpleDelegator | |
def foo | |
puts "foo #{self} #{self.class}" | |
end | |
end | |
D.new("jojo").foo | |
class User | |
end | |
module User::Agent | |
def self.extended klass | |
puts "#{self} extended by #{klass}" | |
end | |
def code | |
"007" | |
end | |
end | |
module User::SuperAgent | |
def self.extended klass | |
puts "#{self} extended by #{klass}" | |
end | |
def code | |
"super #{super}" | |
end | |
end | |
puts User.new.extend(User::SuperAgent, User::Agent).code | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment