3 ms·
Does that mean that `x = x + 1` does not work in Ruby? (And always results in `x == 1` or so?)
by albertzeyer 15y ago
Does that mean that `x = x + 1` does not work in Ruby? (And always results in `x == 1` or so?)
- cheald 15y agoIf x is initialized to an integer (or more accurately, any object that has a method "+" defined that knows how to accept a Fixnum parameter), it'll work fine. If it's not, you'll get "No method + for nil", since what's happening is that you're trying to invoke a method named "+" on the variable named "x" with the parameter "1".
- deleted 15y ago[deleted]