Call and Response (.respond_to)


I am really confused how .respond_to works. According to the hint "Remember, you'll need to pass .respond_to? a symbol." This is confusing me. Why is that I have to pass it as a symbol? Why can't I use age.respond_to(.next) instead?

age = 26



.next isn't a value, :next is a value representing the text "next", similar to a string. The respond_to? method has some particular behaviour, so if you give it other information it won't know what to do with it. As described here though, it'll also accept strings

> (5).respond_to?("upto")
=> true


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.