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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:49:56+00:00 2026-05-20T04:49:56+00:00

I am working on a ruby program and have run into the following problem.

  • 0

I am working on a ruby program and have run into the following problem.

I have two classes AClass and BClass as follows:

class AClass
  attr_accessor :avar
  def initialize(input)
    @avar = input
  end
end

class BClass
  def BClass.build(aclass)
    bvalue = aclass.avar
    ....
  end
end

When i run:

aclass = AClass.new           
puts aclass.avar              
bclass = BClass.build(aclass) 

The first two lines work fine. aclass is intialized and avar is put out to the screen, but the third line creates an error. I seems that the BClass build method can not access the AClass instance variable. What do I need to do to make this work. I thought the attr_accessor would enable me to access the AClass instance variables. Thanks in advance for your input.

  • 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-20T04:49:56+00:00Added an answer on May 20, 2026 at 4:49 am

    If you want to create a new type of initializer for BClass, you can do the following:

    class AClass
      attr_accessor :avar
    
      def initialize(input)
        @avar = input
      end
    end
    
    class BClass
      attr_accessor :bvalue
    
      def self.build(aclass)
        bclass = self.new
        bclass.bvalue = aclass.avar
        bclass
      end
    end
    
    aclass = AClass.new 'ruby'
    bclass = BClass.build aclass
    

    This will set bclass.bvalue = aclass.avar = ‘ruby’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a game (using Ruby) and planning to have it available in
I have a SOAP client in Ruby that I'm trying to get working with
I have been trying to create a Ruby program that will be running online
I'm learning Ruby and working on my first real project. The program will receive
I have working fine my installation of Ruby on Rails on my Snow Leopard.
I'm working on a small Ruby program that will connect to a remote MySQL
I'm working on learning TDD while writing some small ruby programs. I have the
From my time working with Ruby On rails, there is a couple different packaged/projects
For a project I am working on in ruby I am overriding the method_missing
I came from Java, and now I am working more with Ruby. One language

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.