Weird ruby behavior. Can someone explain it?

ruby

Solution

I think what you are doing is converting a.yo into a complex number. If you put in a `puts a.yo.i.class` it returns `Complex`.

I think what you should be doing is:

a = Expe.new
puts a.yo #=> 3 
puts a.i  #=> 3 (returning the 'i' attribute of a)

You can see it clearly by just calling the `.i` function on an integer

puts 3.i  #=> 0+3i  (convert integer 3 to complex)

Problem

I was playing with ruby interpreter, then it happened. How? ``` class Expe attr_reader :i def yo @i = 3 end end a = Expe.new puts a.yo.i #=> 0+3i ```

Original source