我正在学习Ruby Koans,并且我被about_objects.rb中的test_every_object_has_an_id方法挂住了。
def test_every_object_has_an_id
obj = Object.new
assert_equal __, obj.object_id.class
end我知道答案是Fixnum,但是,每当我运行path_to_enlightenment.rb时,我都会收到以下错误消息:
custom_require.rb:36:in `require':about_objects.rb:50: syntax error, unexpected $end, expecting keyword_end (SyntaxError) from rubygems/custom_require.rb:36:in `require'
from path_to_enlightenment.rb:7:in `<main>'提供的代码中是否存在某种bug,或者我做错了什么?
发布于 2014-11-26 07:50:47
缺少end关键字
在您的文件中的其他地方,您丢失了一个end关键字。在找到预期的关键字之前,某个文件已到达源文件的末尾。该错误清楚地告诉您:
custom_require.rb:36:in `require':about_objects.rb:50: syntax error, unexpected $end, expecting keyword_end (SyntaxError) from rubygems/custom_require.rb:36:in `require' from path_to_enlightenment.rb:7:in `<main>'检查命名文件的第7、36和50行。这是您需要解决的问题,与以下事实无关:
Object.new.object_id.class
#=> Fixnum发布于 2014-11-26 07:27:48
它不会问你是哪个类,它会问Fixnum类是什么。所以答案一定是Object
>> Object.new.object_id.class.is_a? Fixnum
#=> false
>> Object.new.object_id.class.is_a? Object
#=> truehttps://stackoverflow.com/questions/27138552
复制相似问题