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

  • SEARCH
  • Home
  • 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 8169751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:56:43+00:00 2026-06-06T20:56:43+00:00

This is a follow up from Creating a class which inherits from another class

  • 0

This is a follow up from Creating a class which inherits from another class in Ruby and m.one + m.two + m.three doesn’t work. We are applying for App Academy which is a Learn to Code course for people with little or no experience. As a result, these questions are similar, but I felt the answers in the other two posts did not address an answer, but diverged to explaining tangential concepts (which I did utilize)

To follow up on the first two mentioned links, I am having a problem with inherited classes. I have the Musician class which is inheriting three variables from the Person class. My problem is that when I run the

m.first_name + " " + m.last_name + ": " + m.age.to_s

I get an error: person.rb:31: undefined method `+’ for nil:NilClass (NoMethodError). I understand that this error has the answer, but I am not yet adept at understanding what this means.

One point to mention is that the query above, must be the way it is. I can not put Puts in front of it.

I would appreciate any suggestions as to why I am getting this statement regarding + being an undefined method.

Thanks!

edit: Thanks for the quick response. I didnt realize the coding community was so active! This is really amazing. I am going to edit the code to reflect the newest issues, so I dont keep getting the same suggestions.

  • 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-06T20:56:46+00:00Added an answer on June 6, 2026 at 8:56 pm

    I get an error: person.rb:31: undefined method `+’ for nil:NilClass (NoMethodError). I understand that this error has the answer, but I am not yet adept at understanding what this means.

    It means that one of the three variables is nil, i.e., it lacks a value:

    m.first_name
    m.last_name
    

    This is occurring because you are returning the result of calling the puts function in all of your accessors. You need to return the variables themselves, not print them and return the result of the print function.

    Also, since you are already using attr_reader you have get methods created for you already. That’s the whole point of using attr_reader; it creates a function which returns an underlying instance variable for you, you simply need to initialize it.

    for example, this:

    class Foo
      def bar
        @bar
      end
    end
    

    is equivalent to

    class Foo
      attr_reader :bar
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow on from another question ( https://stackoverflow.com/questions/10712659/c-class-design-for-monte-carlol-simulation ) I am planning
This is a follow-on from this question, in which I was trying to suppress
This is a follow-on question from the one I asked here . Can constraints
This question is a follow on from this one ... I am binding to
I am creating a java app. I have one class q2a2 which is a
This is a follow up from my previous question I have this code basically
This is a follow-on from a previous SO question Anchoring CSS Repeating Background Image
This is a follow up from a question of mine that was just answered
This is a follow on from my previous question although this is about something
I am trying to follow this example (from p137 of Rob Pickering's Foundations of

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.