Why does this method only accept symbols and not strings as its arguments?
x = 10
x.respond_to?(next)
Pushing a string like the above would throw (ruby):1: void value expression
.
It does accept strings:
x = 10
x.respond_to?('next')
# => true
Your problem is that you didn't pass string, but next
keyword.
From Ruby respond_to? doc:
respond_to?(symbol, include_all=false) → true or false
respond_to?(string, include_all=false) → true or false
It accepts both, symbol and string. And if string passed it is converted to a symbol.
As mentioned by Marek, you didn't pass string, neither symbol and have a syntax error with built-in keyword.