Last active
March 7, 2020 10:24
-
-
Save goodviber/97cc3e48b3a31daaf361354096c23849 to your computer and use it in GitHub Desktop.
stuart
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 Movement | |
attr_reader :distance | |
def initialize(distance) | |
@distance = distance | |
end | |
def move | |
puts "moved #{@distance} miles" | |
end | |
end | |
class Tesla | |
def initialize | |
@movement = Movement.new(2) | |
end | |
def move | |
@movement.move | |
end | |
end | |
class Ford | |
def initialize | |
@movement = Movement.new(3) | |
end | |
def move | |
@movement.move | |
end | |
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
class Vehicle | |
attr_reader :driver, :distance | |
def initialize(driver) | |
@driver = driver | |
@distance = 0 | |
end | |
def self.move(vehicle) | |
vehicle.move | |
end | |
end | |
class Bicycle < Vehicle | |
def move | |
@distance += 2 | |
end | |
end | |
class Motorbike < Vehicle | |
def move | |
@distance += 4 | |
end | |
end | |
class Car < Vehicle | |
def move | |
@distance += 6 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment