Last active
August 26, 2016 18:08
-
-
Save droberts-sea/17099a4d34617e961799a6080621ef18 to your computer and use it in GitHub Desktop.
Bicycle example
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
module Transportation | |
class Vehicle | |
def vechicle_method() | |
puts "I am a vehicle" | |
end | |
end | |
class Bicycle < Vehicle | |
attr_accessor :gear, :speed | |
def initialize() | |
@gear = 5 | |
@speed = 0 | |
end | |
def pedal() | |
@speed += 1 | |
end | |
def brake() | |
@speed -= 1 | |
end | |
def vechicle_method() | |
puts "Bicycle vehicle method" | |
end | |
end | |
end | |
class MountainBike < Transportation::Bicycle | |
attr_accessor :seat_height | |
def initialize() | |
super() | |
@seat_height = 4 | |
end | |
def adjust_seat(amount) | |
@seat_height += amount | |
end | |
def brake() | |
# Mountain bikes have disc brakes | |
@speed -= 3 | |
end | |
def vechicle_method() | |
super() | |
end | |
end | |
mb = MountainBike.new() | |
puts "speed: #{mb.speed}" | |
mb.pedal | |
puts "speed: #{mb.speed}" | |
mb.brake | |
puts "speed: #{mb.speed}" | |
puts "seat height: #{mb.seat_height}" | |
mb.adjust_seat(8) | |
puts "seat height: #{mb.seat_height}" | |
mb.vechicle_method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment