Ruby, Problems Using a Class Derived From "Array"

I'm coding a "deck building" card game. I've created a class called "Deck" that's derived from "Array." The problem I'm having is if I want to use any of the behaviors of arrays for example: discard_pile = other_deck.pop(5) Even if I've established that a particular array is a "Deck", it gets replaced by an array that is not a "Deck", and will no longer do any of the behaviors I've programmed into the "Deck" class. I'm thinking the simplest solution might be to get rid of the "Deck" class. Is there a way to use the functions of arrays while keeping my deck a "Deck"?

7th Aug 2018, 7:22 PM
Benjamin Lee
Benjamin Lee - avatar
1 Answer
+ 1
iirc pop() returns an array so you'll have to overload the function for decks to make it return a deck
7th Aug 2018, 10:00 PM
hinanawi - avatar