Subject(aclass)returns本身在一个方法中
Subject (a class) returns itself in a method
我正在做课程练习,我必须编写代码才能通过以下测试:
it 'returns itself when exiting a journey' do
expect(subject.finish(station)).to eq(subject)
end
我写过:
class Journey
...
def finish(station)
Journey
end
...
end
我收到错误:
expected: #<Journey:0x00007fd90091e7c8>
got: Journey
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-#<Journey:0x00007fd90091e7c8>
+Journey
我写的时候感觉有点太容易了,但我不知道还能怎么做。任何帮助将不胜感激,谢谢!
您正在 returnclass
def finish(station)
Journey
end
但您需要 return 一个实例:
def finish(station)
Journey.new
end
但这还不够好,因为您需要 return 与调用该方法的对象相同的实例"
def finish(station)
self
end
我正在做课程练习,我必须编写代码才能通过以下测试:
it 'returns itself when exiting a journey' do
expect(subject.finish(station)).to eq(subject)
end
我写过:
class Journey
...
def finish(station)
Journey
end
...
end
我收到错误:
expected: #<Journey:0x00007fd90091e7c8>
got: Journey
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-#<Journey:0x00007fd90091e7c8>
+Journey
我写的时候感觉有点太容易了,但我不知道还能怎么做。任何帮助将不胜感激,谢谢!
您正在 returnclass
def finish(station)
Journey
end
但您需要 return 一个实例:
def finish(station)
Journey.new
end
但这还不够好,因为您需要 return 与调用该方法的对象相同的实例"
def finish(station)
self
end