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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:27:36+00:00 2026-05-17T20:27:36+00:00

Example for array arr = [a, b, c] # TODO create an alias for

  • 0

Example for array

arr = ["a", "b", "c"]
# TODO create an alias for arr[1] as x
x = "X"
# arr should  be ["a", "X", "c"] here

Example for hash

hash = { :a => "aaa", :b => "bbb" , :c => "ccc" }
# TODO create an alias for hash[:b] as y
y = "YYY"
# hash should be { :a => "aaa", :b => "YYY" , :c => "ccc" } here

And also an alias for a variable?

var = 5
# TODO create an alias for var as z
z = 7
# var should be 7 here

Motivation: I have a big large deep construct of data, and you can imagine the rest. I want to use it in a read-only manner, but due to performance reasons copy is not permissible.

Metaphor: I want to choose context from a larger data structure and I want to access it with a short and simple name.

UPDATE: Problem solved as sepp2k advised. I just want to draw a summarizing picture here about the solution.

irb(main):001:0> arr = [ { "a" => 1, "b" => 2}, { "x" => 7, "y" => 8 } ]
=> [{"a"=>1, "b"=>2}, {"x"=>7, "y"=>8}]
irb(main):002:0> i = arr[0]
=> {"a"=>1, "b"=>2}
irb(main):004:0> j = arr[1]
=> {"x"=>7, "y"=>8}
irb(main):007:0> j["z"] = 9
=> 9
irb(main):008:0> j
=> {"x"=>7, "y"=>8, "z"=>9}
irb(main):009:0> arr
=> [{"a"=>1, "b"=>2}, {"x"=>7, "y"=>8, "z"=>9}]
  • 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-17T20:27:37+00:00Added an answer on May 17, 2026 at 8:27 pm

    What you want is not possible. There is no feature in ruby that you could use to make your examples work like you want.

    However since you’re saying you want to only use it read-only, there is no need for that. You can just do x = myNestedStructure[foo][bar][baz]. There will be no copying involved when you do that. Assignment does not copy the assigned object in ruby.

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

Sidebar

Related Questions

If I have for example this array-variable: var arr=[ [1,2,3] [4,5,6] ] How can
here is my problem I have the following array (for example) string[] arr =
I have an array from ten (or more) numbers, for example: arr[1,2,3,4,5,6,7,8,9,10] I want
This is an example: class a { private $arr = NULL; public function __construct(array
I'm having an array arr of maps, for example arr == [ { pos
Example: var arr_1:Array = new Array(); arr_1.push({sdate:2010-02-02,status:New}); arr_1.push({sdate:2010-02-03,status:New}); arr_1.push({sdate:2010-02-04,status:New}); arr_1.push({sdate:2010-02-05,status:New}); How can i change
I have an array of 4 characters, for example: char char_array[10]; char_arr[0] = 'a';
Example array $myArray[0] = array('23', null, '43', '12'); $myArray[1] = array(null, null, '53', '19');
For example array ( product1_quantity => 5, product1_quantity => 1, product2_quantity => 3, product2_quantity
I have an array of as given below. For example: array = [20%,*,30%, 10%]

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.