Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6208499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:49:10+00:00 2026-05-24T05:49:10+00:00

It seems as if my code never runs through the switch statement. Every time

  • 0

It seems as if my code never runs through the switch statement. Every time I create a Deck object, every Card object has nil for both the suit and the name. Can anyone help me out?

class Card
def initialize (suit, number, name)
    @suit = suit
    @number = number
    @name = name         #
end
attr_reader :suit, :number, :name
end

class Deck
      def initialize
          @deck = Array.new
          for i in 0...4
              suit = case i
                  when i == 0 then "Spades"
                  when i == 1 then "Hearts"
                  when i == 2 then "Diamonds"
                  when i == 3 then "Clubs"
              end
          puts i
          puts suit     #Debug only
          for j in 2...15
              name = case j
                  when j == 2 then "Two of #{suit}"
                  when j == 3 then "Three of #{suit}"
                  when j == 4 then "Four of #{suit}"
                  when j == 5 then "Five of #{suit}"
                  when j == 6 then "Six of #{suit}"
                  when j == 7 then "Seven of #{suit}"
                  when j == 8 then "Eight of #{suit}"
                  when j == 9 then "Nine of #{suit}"
                  when j == 10 then "Ten of #{suit}"
                  when j == 11 then "Jack of #{suit}"
                  when j == 12 then "Queen of #{suit}"
                  when j == 13 then "King of #{suit}"
                  when j == 14 then "Ace of #{suit}"
              end
              puts j
              puts name   #Debug only
              @deck.push(Card.new(suit, j, name))
          end
      end
  end
  attr_reader :deck    
end          
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:49:11+00:00Added an answer on May 24, 2026 at 5:49 am

    The case statement implicitly applies the === operator. So you want something more like:

    case j
    when 2 then "Two of #{suit}"
    when 3 then "Three of #{suit}"
    # ...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following piece of code seems to unreliably execute and after and undeterministic time
I notice that modern C and C++ code seems to use size_t instead of
It seems like my code works to check for null if I do if
It seems like deployment of VSTO code is very cumbersome. My use case is
First check out this code. I seems like it should work for me, but
I've got some code which draws data from an xml file but it seems
Based on the code I've found, it seems that the Visitor is required to
In the following code, both amp_swap() and star_swap() seems to be doing the same
Currently I`m using Visual Studio for writing code in C++. But it seems so
I just stumbled unto a weirdness in my JSP code. It seems that a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.