type conversion to integer in ruby -
i using latest ruby version[ruby 2.4.1p111]
i getting result of '123'.to_i +12
171
irb(main):021:0> '123'.to_i + 12 => 135 irb(main):022:0> '123'.to_i +12 => 171 irb(main):023:0> 123 + 12 => 135 irb(main):024:0> 123 +12 => 135
can me understand second operation here.
you ended calling unary plus operator in second example, which
returns receiver’s value
and ended (essentially):
'123'.to_i 12
and since, to_i
takes argument, base
, ended converting '123'
integer in base 12, is, apparently, 171.
Comments
Post a Comment