嗨,我正在研究Ruby Koans。我想知道爲什麼ArgumentError
會在下面的代碼中返回Dog6.new
?爲什麼Ruby代碼會生成一個ArgumentError?
class Dog6
attr_reader :name
def initialize(initial_name)
@name = initial_name
end
end
def test_initialize_provides_initial_values_for_instance_variables
fido = Dog6.new("Fido")
assert_equal "Fido", fido.name
end
def test_args_to_new_must_match_initialize
assert_raise(ArgumentError) do
Dog6.new
end
end
是因爲Dog6.new
沒有任何參數?謝謝!!
謝謝你的解釋!現在我明白了:) – Penny