Created
March 27, 2015 10:14
-
-
Save KamilLelonek/07dc2e386d718caf58a9 to your computer and use it in GitHub Desktop.
How to delegate methods in Ruby
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 LazyEmployee | |
def initialize(sandwich_maker) | |
@sandwich_maker = sandwich_maker | |
end | |
def make_me_a_sandwich | |
sandwich_maker.make_me_a_sandwich | |
end | |
private | |
attr_reader :sandwich_maker | |
end |
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
[1] (pry) main: 0> sandwich_maker = SandwichMaker.new | |
=> #<SandwichMaker:0x007f8a528331a8> | |
[2] (pry) main: 0> lazy_employee = LazyEmployee.new(sandwich_maker) | |
=> #<LazyEmployee:0x007f8a52240930 @sandwich_maker=#<SandwichMaker:0x007f8a528331a8>> | |
[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