Skip to content

Instantly share code, notes, and snippets.

@ro31337
Created September 9, 2017 02:05
Show Gist options
  • Select an option

  • Save ro31337/6e3c9b6165012ee35739f74aa9e3ca25 to your computer and use it in GitHub Desktop.

Select an option

Save ro31337/6e3c9b6165012ee35739f74aa9e3ca25 to your computer and use it in GitHub Desktop.
class Car
attr_reader :num
attr_reader :seats
def initialize(num, seats)
@num = num
@seats = seats
end
end
cars = [
Car.new(3, 12),
Car.new(4, 9),
Car.new(1, 10),
Car.new(2, 8),
Car.new(5, 19)
]
input = gets.chomp.to_i
index = cars.find_index { |car| car.num == input }
car = cars[index]
p "Car has #{car.seats} seats"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment