From: Rob Marshall Date: 2011-12-09T02:09:10+09:00 Subject: Re: Confusing results from string multiplication Hi Robert, Well, for someone who is new to Ruby, how would I, or anyone for that matter, know that doing: '11.to_s *2' converts the number 11 to binary when '11.to_s * 2' and 11.to_s*2 both do string multiplication as expected. Especially since whitespace isn't supposed to matter. Sorry, seems very confusing to me...Not that I think something like this happens all that often, but it would be a potentially hard bug to track down. I could probably look at it all day and not know why the math wasn't working. For example: >> ((11.to_s *2).to_i/2) => 505 There's no way that 11 in binary (1011) converted back to an integer should ever give me 505 when divided by 2! And I realize that that's not actually what's happening here, because what's happening is that 11 is being converted to binary and then to a string, which means that the precedence is either wrong or confusing. Because the only way I get to 1011 is if the '*2' happens BEFORE the .to_s. Which means that the precedence seems to be (in this case, and potentially in this case only) to do the *2 BEFORE converting 11 to a string, which is just wrong, in my opinion. And if *x is really: "splash x", i.e. split the list x into it's individual components, why does '11.to_s*2' do the string multiplication as expected? Shouldn't it also convert 11 to binary? Does this still happen on 1.9.3? Rob -- Posted via http://www.ruby-forum.com/.