Untitled
unknown
ruby
2 years ago
1.1 kB
8
Indexable
class Train attr_writer :speed attr_reader :speed def initialize(number, type, qtywagons) @number = number.to_i @type = type @qtywagons = qtywagons.to_i @speed = 0 end def break_speed @speed = 0 end def show_wagons puts "Qty of wagons = #{@qtywagons}" end def add_wagons if @speed == 0 @qtywagons += 1 else puts 'Train is moving' end end def remove_wagons if @speed == 0 @qtywagons -= 1 else puts 'Train is moving' end end def get_route(route) @route = route end def current_station @current_station = @snames end end class Route attr_reader :snames def initialize(first, last) @snames = [first, last] end def add_station(sname) @snames.insert(-2, sname) end def show_allstations puts "#{@first}, #{@sname}, #{@last}" end def delete_station(sname) @sname.delete(sname) end end
Editor is loading...