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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:13:35+00:00 2026-06-12T04:13:35+00:00

Recently started learning ruby and I’ve created a class for family members that contains

  • 0

Recently started learning ruby and I’ve created a class for family members that contains name, age, sex, marital status, and traits. I am trying to write a method that will determine if a family member is a parent and if whether or not its the mother or the father.

so the code for the method is as follows:

def is_father?(age, sex)
    if age > 30
      puts "is parent"
          if sex == "Male"
            then puts "is father"
          else puts "not father"
          end
    end
  end

And a family member might look like this:

fm1=Family.new("John", "Male", 54, "Married", "Annoying")

after being initialized like this:

class Family
  def initialize(name, sex, age, status, trait)
    @fam_name=name
    @fam_sex=sex
    @fam_age=age
    @fam_stat=status
    @fam_trait=trait
  end
end

If a person contains the previously mentioned characteristics, how do I just pass age + sex into this method? Thanks in advance for your help

  • 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-12T04:13:36+00:00Added an answer on June 12, 2026 at 4:13 am

    You must store your data during initialization in attributes. later you can use them without using parameters of the method.

    Example:

    class Family
       def initialize(name, sex, age, status, trait)
        @fam_name=name
        @fam_sex=sex
        @fam_age=age
        @fam_stat=status
        @fam_trait=trait
      end
      def is_parent?; @fam_age > 30;end
      def is_father?
        is_parent? and @fam_sex == "Male"
      end
      def to_s
        result = @fam_name.dup
        if @fam_age > 30
          result <<  " is parent and is "
              if @fam_sex == "Male"
                result << "father"
              else 
                result << "not father"
              end
          end
        result
      end
    end
    
    fm1=Family.new("John", "Male", 54, "Married", "Annoying")
    puts fm1.ilding is_parent?
    puts fm1.is_father?
    puts fm1
    

    Remarks:

    • I modified your is_father? – methods ending on ? normally returns a boolean value.
    • I moved your text building to method to_s. to_s is called if you print your object with puts.
    • Better you avoid puts inside your methods. Most of the times, it is better to return an answer string and make the puts when you call the method.

    Perhaps I misunderstand your request.

    If is_father? is no method of Family and you need access to the attributes, then you must define a getter method:

    class Family
      def initialize(name, sex, age, status, trait)
        @fam_name=name
        @fam_sex=sex
        @fam_age=age
        @fam_stat=status
        @fam_trait=trait
      end
      attr_reader :fam_sex
      attr_reader :fam_age
    end
    
    fm1=Family.new("John", "Male", 54, "Married", "Annoying")
    puts fm1.fam_sex
    puts fm1.fam_age
    
    
    is_father?(fm1.fam_age, fm1.fam_sex)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started learning ruby, and I understood that you coud use code blocks
Recently I have started learning rails and was a little surprised that the default
I have started learning Ruby recently and I was trying out the following piece
I have recently started learning C++ and coming from a Ruby environment I have
I have recently started learning Ruby, as my first programming language. I feel comfortable
I've recently started learning SWT (on class #4, to be precise) due to business
I recently started learning Java and found it very strange that every Java public
I've recently started learning Scala and was disappointed (but not surprised) that their generics
I recently started learning Ruby and Ruby on Rails, and have watched a plethora
I recently started learning Objective-C. I decided to make a class called Student with

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.