The commutative property of multiplication in Ruby

Viewed 201

In ruby, I was messing around in the irb and found two code samples that should work the same but don't

"a" * 4     #this is "aaaa"
4 * "a"     #this is "String can't be coerced into a Fixnum"

Doesn't this violate the commutative property of multiplication?

4 Answers
Related