ruby - A nil class when trying to initialize a deck of cards -


the following code resulting in nil , can't figure out why. there wrong initialization?

class card     values = %w(2 3 4 5 6 7 8 9 10 j q k a)     suits = %w(s h d c)      def initialize(suit, value)         @suit = suit         @value = value     end end  class deck     attr_accessor :cards      def initialize         @cards = []         card::suits.each |suit|             card::values.each |value|                 @cards << card.new(suit, value)             end         end     end end  deck.new  p @cards 

you create new object deck.new, don't print value of cards - print @cards instance variable in context nil.

you wanted p deck.new.cards.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -