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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:40:07+00:00 2026-05-16T02:40:07+00:00

How do I assign a value to another class’s initialize parameter in Ruby class

  • 0

How do I assign a value to another class’s initialize parameter in Ruby

class Ubac
  def initialize(p_str)
    @p_str=p_str
    (.....)
  end
  def method1
    (.....)
  end

end

class ReqQuote < Ubac
  def initialize(p_code)
     @code=p_code
     # here how do i initialize the @p_str to the value which is returned from the get_data method below.?
  end
  def get_data(symbol)
     (....) # fetch data
     data 
  end
  def methodx
    (.....)
  end


end

Here how do I initialize @p_str with the value which is returned from the get_data method as if p_str was initialized from the Ubac class’s initialize?

  • 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-16T02:40:07+00:00Added an answer on May 16, 2026 at 2:40 am

    In this specific case you can just put @p_str= in Ubac#initialize. However, you can call Ubac‘s initialize from ReqQuote using super e.g.

    class ReqQuote < Ubac
      def initialize(p_code)
         super(get_data(some_symbol))
         @code=p_code
      end
      ...
    

    This is generally a good practice because it means any other initialisation code added to Ubac will also get executed when you create a ReqQuote.

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

Sidebar

Related Questions

A struct is a value type, so if I assign a struct to another
I have a about 80 properties in a class, i assign each value in
Another newbie issue. I have a situation where I have to assign a value
I have been trying to assign value to an object array that is defined
To assign specific value to 1D array I'm using LINQ like so: int[] nums
I want to assign a value from a select box to an input field
how can I assign a value to the 'extraParams' property of the following plugin
I have to assign the value in a repeater column in such a way
I want to assign the value in QString to a const std::string QString qfile(some
can we assign null value to struct type of variable? struct MyStruct { }

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.