Ruby Koans 202: Why does the correct answer give a syntax error?
Posted
by
hlh
on Stack Overflow
See other posts from Stack Overflow
or by hlh
Published on 2012-10-12T15:27:40Z
Indexed on
2012/10/12
15:37 UTC
Read the original article
Hit count: 183
I'm working through the about_classes.rb file in the Ruby Koans, and have hit a brick wall with the "inside_a_method_self_refers_to_the_containing_object" test. Here's the code:
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
So, I'm trying to make the first half of the assert_equal
evaluate to the second half (fidos_self). When I work it out in irb, fidos_self returns <Dog named 'Fido'>
, but I keep receiving a syntax error for that answer.
I've seen this similar post:
Ruby Koans: Where are the quotes in this return value?, but his solution (putting fido
instead of <Dog named 'Fido'>
) causes my rake to abort, saying the stack level is too deep.
This is driving me nuts. What am I missing here?
© Stack Overflow or respective owner