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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:02:45+00:00 2026-06-06T22:02:45+00:00

Say we have deep hashes like: b = {1 => {2 => {} },

  • 0

Say we have “deep hashes” like:

b = {1 => {2 => {} }, 4 => {} }
a = {1 => {2 => {3 => {} }}, 4 => {}, 5 => "123" }

or

b = {1 => {children: {2 => {children: false} }}}
a = {1 => {name: "name", surname:"sur", children: {2 => {name: "name", surname:"sur", children: false}}}, 3 => {}}

a includes b but not versa vice;

Here’s my try:

class Hash

  def >=(b)
    eq ||= true     
    b.each do |k, v| 
      if !(self.include? k) 
        eq = false 
      elsif ( ((self[k]&&v).is_a? Hash) && !((v||self[k]).empty?) )
        self[k]>=v 
      end 
    end

    return eq
  end
end

a >= b # true
b >= a # false

Short version:

class Hash

  def >=(b)  
    eq = true
    b.each { |k, v| eq &= !(self.include? k) ? false : ( ( ((self[k]&&v).is_a? Hash) && !((v||self[k]).empty?) ) ? self[k]>=v : true)}

    return eq
  end
end

My question: is there more graceful way to do that?

  • 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-06T22:02:47+00:00Added an answer on June 6, 2026 at 10:02 pm

    Functional approach:

    class Hash
      def >=(other)
        other.all? do |key, value|
          if self.has_key?(key) 
            value.is_a?(Hash) ? (self[key].is_a?(Hash) && self[key] >= value) : (self[key] == value)
          else
            false
          end
        end 
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say i have a few fields like the following: abd738927 jaksm234234 hfk342 ndma0834 jon99322
Say I have a struct defined somewhere deep in low-level code used all over
Let's say we have data as follows var data = { facets: [{ name
Explanation: Let's say I have an object graph that's nested several levels deep and
So pretty straight forward but I cant find the answer. Say I have an
There are questions LIKE this one, but they are not similar enough to my
This makes me fee like a knucklehead but how do I say previousError =
So lets say I want to make a deep copy of an object, but
Lets say have this immutable record type: public class Record { public Record(int x,
Say I have a select box eg <div data-bind='visible: someProp'> <select class=selectSubWidgets data-bind='options: subWidgets,optionsText:

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.