I found that when using bracket notation on the number 100
in Ruby, I get this:
irb(main):001:0> 100[0]
=> 0
irb(main):002:0> 100[1]
=> 0
irb(main):003:0> 100[2]
=> 1
So I assumed it was getting the digits, indexed like this:
NUMBER: 1|0|0
-----
INDEX: 2|1|0
I tried this on the number 789
with unexpected results.
irb(main):004:0> 789[0]
=> 1
irb(main):005:0> 789[1]
=> 0
irb(main):006:0> 789[2]
=> 1
I would expect it to return 9
, then 8
, then 7
if it was getting the digits. From this result, that is clearly not happening, so what exactly does using bracket notation on a number do?