Skip to content

Instantly share code, notes, and snippets.

@Rafe
Created May 21, 2019 18:06
Show Gist options
  • Save Rafe/939e736c88dfc5c098dfb2f00519b5f4 to your computer and use it in GitHub Desktop.
Save Rafe/939e736c88dfc5c098dfb2f00519b5f4 to your computer and use it in GitHub Desktop.
class Bicycle
attr_reader :size, :chain, :tire_size
def initialize(args = {})
@size = args[:size]
@chain = args[:chain]
@tire_size = args[:tire_size]
end
def self.default_chain
'10-speed'
end
def spares
{tire_size: tire_size,
chain: chain}
end
end
class RoadBike
attr_reader :bike, :tape_color
def initialize(args={})
@bike = Bicycle.new(default_args.merge(args))
@tape_color = args[:tape_color]
end
def default_args
{
chain: Bicycle.default_chain,
tire_size: default_tire_size
}
end
def spares
bike.spares.merge({
tape_color: tape_color
})
end
def default_tire_size
'23'
end
end
class MountainBike
attr_reader :bike, :front_shock, :rear_shock
def initialize(args={})
@bike = Bicycle.new(default_args.merge(args))
@front_shock = args[:front_shock]
@rear_shock = args[:rear_shock]
end
def default_args
{
chain: Bicycle.default_chain,
tire_size: default_tire_size
}
end
def spares
bike.spares.merge({
rear_shock: rear_shock
})
end
def default_tire_size
'2.1'
end
end
class RecumbentBike
attr_reader :bike, :flag
def initialize(args={})
@bike = Bicycle.new(default_args.merge(args))
@flag = args[:flag]
end
def spares
bike.spares.merge(flag: flag)
end
def default_args
{
chain: default_chain,
tire_size: default_tire_size
}
end
def default_chain
'9-speed'
end
def default_tire_size
'28'
end
end
bent = RecumbentBike.new(flag: 'tall and orange')
bent.spares
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment