Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Last active March 28, 2017 21:30
Show Gist options
  • Save KamilLelonek/9ef7ef3a6e88e014f3d3 to your computer and use it in GitHub Desktop.
Save KamilLelonek/9ef7ef3a6e88e014f3d3 to your computer and use it in GitHub Desktop.
How to delegate methods in Ruby
class LazyEmployee < SimpleDelegator
def initialize(sandwich_maker)
super
end
end
[1] (pry) main: 0> sandwich_maker = SandwichMaker.new
=> #<SandwichMaker:0x007fbfa49aeb40>
[2] (pry) main: 0> lazy_employee = LazyEmployee.new(sandwich_maker)
=> #<SandwichMaker:0x007fbfa49aeb40>
[3] (pry) main: 0> lazy_employee.make_me_a_sandwich
OKAY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment