2012-08-24 40 views
8

lẽ là dấu hiệu của một người nghiệp dư mà tôi đang tự hỏi nếu vấn đề là công án (chứ không phải tôi), tuy nhiên, hãy xem xét công án nàyRubyKoans: koan bị hỏng?

def test_calling_global_methods_without_parentheses 
    result = my_global_method 2, 3 
    assert_equal __, result 
    end 

Lưu ý, phương pháp my_global là

def my_global_method(a,b) 
    a + b 
end 

Đây là gợi ý nó mang lại cho tôi tại nhà ga

The answers you seek... 
    <"FILL ME IN"> expected but was <5>. 

Vì vậy, tôi đã làm

def test_calling_global_methods_without_parentheses 
    result = my_global_method 2, 3 
    assert_equal 5, result 
    end 

và tôi đã nhận lỗi này

Users/mm/Sites/koans/about_methods.rb:21:in `eval': (eval):1: syntax error, unexpected tINTEGER, expecting keyword_do or '{' or '(' (SyntaxError) 
assert_equal 5, my_global_method 2, 3 
           ^
    from /Users/mm/Sites/koans/about_methods.rb:21:in `test_sometimes_missing_parentheses_are_ambiguous' 
    from /Users/mm/Sites/koans/edgecase.rb:377:in `meditate' 
    from /Users/mm/Sites/koans/edgecase.rb:449:in `block in walk' 
    from /Users/mm/Sites/koans/edgecase.rb:460:in `block (3 levels) in each_step' 
    from /Users/mm/Sites/koans/edgecase.rb:458:in `each' 
    from /Users/mm/Sites/koans/edgecase.rb:458:in `block (2 levels) in each_step' 
    from /Users/mm/Sites/koans/edgecase.rb:457:in `each' 
    from /Users/mm/Sites/koans/edgecase.rb:457:in `each_with_index' 
    from /Users/mm/Sites/koans/edgecase.rb:457:in `block in each_step' 
    from /Users/mm/Sites/koans/edgecase.rb:455:in `catch' 
    from /Users/mm/Sites/koans/edgecase.rb:455:in `each_step' 
    from /Users/mm/Sites/koans/edgecase.rb:448:in `walk' 
    from /Users/mm/Sites/koans/edgecase.rb:470:in `block in <top (required)>' 

Có ai biết vấn đề hoặc bạn có thể cho tôi biết làm thế nào để bỏ qua một công án?

Trả lời

18

Ồ, tôi đã thử nghiệm này koan. Lỗi này nằm trên dòng 21 nếu bạn nhận thấy rằng, không phải là phương thức "test_calling_global_methods_without_parentheses". Đó là phương pháp "test_sometimes_missing_parentheses_are_ambiguous" không đúng. Bạn phải sửa phương thức đó.

def test_calling_global_methods_without_parentheses 
    result = my_global_method 2, 3 
    assert_equal 5, result   # You're fine with this koan. 
end 

# (NOTE: We are Using eval below because the example code is 
# considered to be syntactically invalid).     
def test_sometimes_missing_parentheses_are_ambiguous 
    eval "assert_equal 5, my_global_method 2, 3" # ENABLE CHECK 
    # **LOOK HERE~~~ HERE IS THE ERROR YOU SEE** Just correct it. 

Và nếu có bất kỳ koan nào bạn không biết giải quyết, hãy bình luận.