On Fri, Jan 21, 2011 at 10:44 AM, Josh R. [email protected] wrote:
puts “you drew the card #{$deck[draw].name}”
$deck.delete(draw)
end
draw
Still, $deck is an Array and you want to delete from $deck and not
from any of the Hashes in the Array!
This is what I think it should look like.
Please rethink.
10:55:44 ~$ ri19 Array#delete Array#delete_at
Array#delete
(from ruby core)
ary.delete(obj) → obj or nil
ary.delete(obj) { block } → obj or nil
Deletes items from self that are equal to obj. If any items are
found, returns obj. If the item is not found, returns nil. If
the optional code block is given, returns the result of block if the
item is not found. (To remove nil elements and get an informative
return value, use #compact!)
a = [ “a”, “b”, “b”, “b”, “c” ]
a.delete(“b”) #=> “b”
a #=> [“a”, “c”]
a.delete(“z”) #=> nil
a.delete(“z”) { “not found” } #=> “not found”
Array#delete_at
(from ruby core)
ary.delete_at(index) → obj or nil
Deletes the element at the specified index, returning that element, or
nil if the index is out of range. See also Array#slice!.
a = %w( ant bat cat dog )
a.delete_at(2) #=> “cat”
a #=> [“ant”, “bat”, “dog”]
a.delete_at(99) #=> nil
10:56:05 ~$
What do you all think regarding using arrays or hashes in my card game?
Any thoughts would be appreciated.
No idea as I don’t know what your game is about and how it is supposed
to be played.
Kind regards
robert