Help me understand this subject.
I’m reading the book “Programming Ruby 1.9 & 2.0” by Dave Thomas, and the Chapter “Standard Protocols and Coercion” explain it but I didn’t understand it.
Why are there 2 versions of conversion to the same datatype?
Why are there
to_ary instead of only one of those? or
As an example, you can see in the following code how depending of the context, sometimes Ruby uses
to_a and some times
class A def to_ary [1, 2] end def to_a [3, 4] end end o = A.new a, b = o puts a, b # outputs 1, 2 a, b = *o puts a, b # outputs 3, 4