On Thu, Jan 20, 2011 at 10:34 AM, Josh Rowe <joshua / wired.com.au> wrote:
> Hello everyone, this is my first post on this forum and I'm quite new to
> ruby. My dilemma is that I've got an array which holds a whole lot of
> arrays inside it and I want to print a element of one of the arrays
> within the overall array. Got it? Here's an example
>
> #!/usr/bin/env ruby
> card1 = ["Ninja Monster", "monster", 1400]
> card2 = ["Ninja Mage", "monster", 1600]
> cdname = 0
> deck = [card1,card2]
> puts deck[0[cdname]]
You're almost there:
puts deck[0][cdname]
Nesting does not apply to indexes. Instead you need to unnest step by
step. Hence the sequence of [idx] operations.
> Does anyone(I'm sure most of you) know how to get this to work with a
> minimal amount of extra code.
See above.
Cheers
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/