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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -