Created
June 4, 2012 16:17
-
-
Save jasonroelofs/2869306 to your computer and use it in GitHub Desktop.
http://spin.atomicobject.com/2012/06/04/bringing-fp-to-oo/ Methods without side effects.
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 Driving | |
def start(car) | |
car.clone.merge(running: true) | |
end | |
def accelerate(car) | |
car.clone.merge(speed: car[:speed] + 1) | |
end | |
def get_in(car, passenger) | |
car.clone.merge(passengers: car[:passengers] + [passenger]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment