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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:57:38+00:00 2026-06-18T00:57:38+00:00

I have some large hashes (>10⁵ keys) with interlocking structures. They’re stored on disk

  • 0

I have some large hashes (>10⁵ keys) with interlocking structures. They’re stored on disk as YAML. I’d like to avoid duplication by using anchors and references in the YAML, but I haven’t been able to figure out if there’s a way to do it implicitly in the hash such that the #to_yaml method will label the anchor nodes properly.

Desired YAML:

--- 
parent1:
  common-element-1: &CE1
    complex-structure-goes: here
parent2:
  uncomment-element-1:
    blah: blah
  <<: *CE1

Ruby code:

hsh = {
  'parent1' => {
    'common-element-1' => {
      'complex-structure-goes' => 'here',
    },
  'parent2' => {
    'uncommon-element-1' => {
      'blah' => 'blah',
    },
    '<<' => '*CE1',
  },
}

The reference is quite straightforward — but how to embed the &CE1 anchor in the 'common-element-1' item in the Ruby hash?

I want to work as much as possible with native Ruby primitive types (like Hash) rather than mucking about with builders and emitters and such — and I definitely don’t want to write the YAML manually!

I’ve looked at Read and write YAML files without destroying anchors and aliases? and its relative, among other places, but haven’t found an answer yet — at least not that I’ve understood.

Thanks!

  • 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-18T00:57:39+00:00Added an answer on June 18, 2026 at 12:57 am

    If you use the same Ruby object, the YAML library will set up references for you:

    > common = {"ohai" => "I am common"}
    > doc = {"parent1" => {"id" => 1, "stuff" => common}, "parent2" => {"id" => 2, "stuff" => common}}
    > puts doc.to_yaml
    ---
    parent1:
      id: 1
      stuff: &70133422893680
        ohai: I am common
    parent2:
      id: 2
      stuff: *70133422893680
    

    I’m not sure there’s a straightforward way of defining Hashes that are subsets of each other, though. Perhaps tweaking your structure a bit would be warranted?

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

Sidebar

Related Questions

I have a large data.frame displaying some weird properties when plotted. I'd like to
I have some document stored as a large String. In the String I have
I have some large pcap (packet capture) files collected with tcpdump. I would like
I have some very large processing being done in a php application. I'd like
We have some large sites on different domains. Let's say x.com and y.com, they
Basic problem I have some large, but logically organised documents - and would like
I currently have some large strings that I would like use as test data
I have a large array of hashes, about 0.5Gb, stored in memory, and I
I have some large chunk of data that I want to send to the
I have an application on the Compact Framework that has some large embedded resources

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.