learning-to-code/ruby/vehicle_methods.rb

29 lines
639 B
Ruby
Raw Permalink Normal View History

2021-01-23 04:16:02 +00:00
def accelerate
puts "Stepping on the gas"
puts "Speeding up"
end
def sound_horn
puts "Pressing the horn button"
puts "Beep beep!"
end
def use_headlights(brightness)
puts "Turning on #{brightness} headlights"
puts "Watch out for deer!"
end
def use_headlights(brightness = "low-beam")
puts "Turning on #{brightness} headlights"
puts "Watch out for deer!"
end
def mileage(miles_driven, gas_used)
return miles_driven / gas_used
end
trip_mileage = mileage(400, 12)
puts "You got #{trip_mileage} MPG on this trip."
lifetime_mileage = mileage(11432, 366)
puts "This car averages #{lifetime_mileage} MPG."