4 ms·
Does nine really end up containing a string like that? I would have expected it to be the number 9.
by tokamak-teapot 5y ago
Does nine really end up containing a string like that? I would have expected it to be the number 9.
- bornelsewhere 5y agoThe example is syntactically incorrect Crystal. Should be nine = while 1; break 9; end puts nine And yes, it prints "9".
- diragon 5y agoWhat is going on with the upvotes here? The incorrect comment by OP is upvoted, while this correct comment is downvoted.
- kawsper 5y agoirb(main):001:0> nine = while 1 do break 9 end => 9 irb(main):002:0> nine.class => Integer irb(main):003:0> puts nine 9 => nil puts might be calling .to_s on the variable, which is why you see a string, but the loop does return an integer.
- quesera 5y agoAnd just to be clear, to_s will return a string, but it will definitely not do the craziness of converting an integer into an English representation of the number! 9.to_s => "9"
- gorgoiler 5y agoSorry. Yes, you are correct. I over-edited my comment to fit a narrow screen, breaking the example.