@Dave - you're right it is partly evil as it changes the type of the object.

Though what you can guarantee is that at the end-point - the object will be guaranteed to have a given type (in this case, an Array). Which is stability of a sort.

This is a different use-case to, say to_a where the resulting object maybe be an array, but you wouldn't want to alter the original variable because you're fundamentally changing the shape of the object.

with to_a you are coercing the thing (whatever it is) into an Array - probably destroying the original object in the process. In this case you still have the original object. Either it is an array already (and so no change) or it becomes an array with the original thing in it...

It seems like you are missing something about Ruby's type system. Duck typing means many objects can produce versions of themselves as other types, but it is also strongly typed, so any given object will remain that kind of object forever, unless you subvert Ruby itself. To_a, coerce and friends never change the type of an object, they just return another. An implementation that destroyed the original object in the process (of, for instance, producing an array) would be broken.There's a big difference between "the object becomes" and "the object's instance method returns".

I haven't missed that, just grumbling about it when it gets in my way :)

I agree that it's totally evil to want something different for the tiny percentage of special cases where I'd actually use it - and I don't know that it really would make the code look better if I did. Just thought it'd be interesting to try and then got curious about how I'd go about doing it if I did.

That's even worse -- a method that changes the class of a passed parameter as a potentially unintended side-effect!The #become method makes it easy to write some surprising code.Perhaps you can accomplish similar things by boxing your object in an array or something, then you can use #replace to swap in other objects freely. I recall some related discussion on a Ref type/class on ruby-talk back in the day, you might enjoy reading some of that.