wrote:
> class CardStack<Array
> def my_shuffle!
> size.times do
> push slice! rand(size)
> end
> self
> end
> end
>
> deck = CardStack.new
>
> deck = [1,2,3,4,5,6]
Unlike C++, = is not a method-based operator in ruby; it's more of a
'keyword operator' that binds a variable to an object. So here what you
are doing is creating a new CardStack, binding deck to it, then creating
a new Array and binding deck to *that* instead. (The new CardStack is
lost, and will be garbage collected). What you need to do, instead, is
deck = CardStack.new([1,2,3,4,5,6])
where CardStack inherits the copy constructor from Array and does indeed
initialise itself properly.
martin