a = [2,4,5]
a.count-1 => 2
a.count - 1 => 2
But
a.count -1 => 0
What causes this behavior? Why doesn’t it happen if a is an integer (and not an array)?
Also, I have noticed that there must not be a space between a method name and the parenthesis that follows (for parameters). Why is that?
Ruby 1.9.2
Because methods can be called with no parentheses, this:
Means subtract 1 from
a.count, whereasMeans call the method
a.countwith-1as an argument. It doesn’t happen whenais an integer because integers don’t have thecountmethod. You just have to be careful as you type.