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 8923185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:03:07+00:00 2026-06-15T07:03:07+00:00

I have a problem with ruby, it won’t load the file i have into

  • 0

I have a problem with ruby, it won’t load the file i have into the designated arrays.

class Dancer
  def Initialize (couplenumber, score1, score2, score3, score4, score5, score6, score7)
    @couplenumber = couplenumber
    @score1 = score1
    @score2 = score2
    @score3 = score3
    @score4 = score4
    @score5 = score5
    @score6 = score6
    @score7 = score7
  end

  def show()
    return "Couple Number: #{@couplenumber}. Scores: #{@score1}, #{@score2}, #{@score3}, #{@score4}, #{@score5}, #{@score6}, #{@score7}."
  end
end

results = File.open("danceresult.txt", "r+")
dancescores = []

# Splitting dance scores with "," and putting into arrays.
for dancers in results
  a = dancers.split(",")
  couplenumber = a[0]
  score1 = a[1]
  score2 = a[2]
  score3 = a[3]
  score4 = a[4]
  score5 = a[5]
  score6 = a[6]
  score7 = a[7]
  dancescores << Dancer.new
end

dancescores.each do |dance|
  puts dance.show
end

My problem is that Ruby only passes this:

Couple Number: . Scores: , , , , , , .
Couple Number: . Scores: , , , , , , .
Couple Number: . Scores: , , , , , , .
Couple Number: . Scores: , , , , , , .
Couple Number: . Scores: , , , , , , .
Couple Number: . Scores: , , , , , , .

I’m not very good at coding and still trying to learn 🙂 Thanks in advance.

  • 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-06-15T07:03:08+00:00Added an answer on June 15, 2026 at 7:03 am

    A few problems here:

    1. The method is called initialize, not Initialize — capitalization is important.

    2. You have a bunch of variables with the same name in different places, you seem to think these will be the same variable, but they aren’t. For example, the score1 in your initialize method is not the same as the one in the line score1 = a[1]. Likewise for couplenumber and so on.

    3. Because of the previous points, what you’re inserting into the array is an empty Dancer object with none of its instance variables set to anything.

    Here’s a corrected version of the code:

    class Dancer
      def initialize(couplenumber, score1, score2, score3, score4, score5, score6, score7)
        @couplenumber = couplenumber
        @score1 = score1
        @score2 = score2
        @score3 = score3
        @score4 = score4
        @score5 = score5
        @score6 = score6
        @score7 = score7
      end
    
      def show()
        return "Couple Number: #{@couplenumber}. Scores: #{@score1}, #{@score2}, #{@score3}, #{@score4}, #{@score5}, #{@score6}, #{@score7}."
      end
    end
    
    results = File.open("danceresult.txt", "r+")
    
    # Splitting dance scores with "," and putting into arrays.
    # Note that we're using map, which handles collecting the results into an array for us
    
    dancescores = results.map |dancers|
      a = dancers.split(",")
      Dancer.new(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7])
    
      # You could more simply write the previous line as
      # Dancer.new(*a[0..7]), but that's
      # essentially just syntactic sugar for the above
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with ruby and json. I have a json-file with information
I've run into a strange problem with Ruby that I can't explain. I have
I am learning Ruby and have to do some homework, but have problem with
I am beginner in ruby + rails. I have problem to get values in
I am looking for the Ruby-est way to solve a problem. I have code
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
I have problem with UIWebView delay when the load image from url. In my
I have a problem with Ruby's openssl library. Here is what I do: In
I'm new to ruby and I have a problem loading gems. I've read every
I just have a problem with a ruby script I just want to change

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.