Skip to content

Commit

Permalink
課題3作成
Browse files Browse the repository at this point in the history
  • Loading branch information
busitora committed Mar 5, 2019
1 parent d8ee1e3 commit ffe44a5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion car.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ class Car
# 定数を追加
UP_SPEED = 10
DOWN_SPEED = 20
MAX_PASSENGERS = 4

@@count = 0
attr_accessor :number, :color
attr_accessor :number, :color, :passengers
# speedは外部から設定しないのでreaderで定義
# @speedが使えるようになる
attr_reader :speed
Expand All @@ -15,6 +16,8 @@ def initialize(number, color)
# @speedを初期化
@speed = 0
@@count += 1
# 運転手を追加
@passengers = 1
end

# 加速用のメソッド追加
Expand All @@ -38,6 +41,16 @@ def speed_down
end
end

# 乗車上限メソッドを追加
def get_on
if @passengers >= MAX_PASSENGERS
puts "乗車できません。この車の最大乗車人数は4人です。"
else
@passengers += 1
puts "乗車しました"
end
end

def self.count
@@count # return @@countの略
end
Expand Down

1 comment on commit ffe44a5

@hiroki-okazaki
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
細かい点で恐縮ですが、get_onメソッド内の”最大乗車人数は4人です”の”4人”の部分をMAX_PASSENGERSにしてあげるとより汎用性が良いのかなと思います!

Please sign in to comment.