Skip to content

Instantly share code, notes, and snippets.

@semarco
Created June 20, 2013 06:09
Show Gist options
  • Save semarco/5820629 to your computer and use it in GitHub Desktop.
Save semarco/5820629 to your computer and use it in GitHub Desktop.
experiment with module extend vs delegation
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