gpt4 book ai didi

ruby 公案 202 : Why does the correct answer give a syntax error?

转载 作者:数据小太阳 更新时间:2023-10-29 07:56:48 26 4
gpt4 key购买 nike

<分区>

我正在研究 Ruby Koans 中的 about_classes.rb 文件,但在“inside_a_method_self_refers_to_the_containing_object”测试中遇到了障碍。这是代码:

class Dog7
attr_reader :name

def initialize(initial_name)
@name = initial_name
end

def get_self
self
end

def to_s
__
end

def inspect
"<Dog named '#{name}'>"
end
end

def test_inside_a_method_self_refers_to_the_containing_object
fido = Dog7.new("Fido")

fidos_self = fido.get_self
assert_equal <Dog named 'Fido'>, fidos_self
end

所以,我正在尝试制作 assert_equal 的前半部分评估下半场 (fidos_self)。当我在 irb 中计算时,fidos_self 返回 <Dog named 'Fido'> ,但我不断收到该答案的语法错误。

我看过类似的帖子: Ruby Koans: Where are the quotes in this return value? ,但他的解决方案(使用 fido 而不是 <Dog named 'Fido'> )导致我的 rake 中止,说堆栈级别太深。

这让我抓狂。我在这里缺少什么?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com