1

I have a nested hash like this where it can have 50 values:

{
 "pool1"=>{"name"=>"my-pool", "partition"=>"Common"},
 "pool2"=>{"name"=>"test-2", "partition"=>"baas"}
}

I am trying to get all of the pools with the key "partition"=>"baas". like this:

 {"pool7"=>{"name"=>"test-7", "partition"=>"baas"}
 {"pool12"=>{"name"=>"test-12", "partition"=>"baas"}
 {"pool18"=>{"name"=>"test-18", "partition"=>"baas"}}

This is how i am trying to do this.

def test(partition_name,hash)
        a = 1
        b = partition_name
        c = {}
        d = 1

        partition_hash.each do |i|

           f = i.fetch(":pool#{a}",{}.fetch(:partition, false))

            if f = b
                c["pool#{d + 1}"] = i
                d = d +1
            end
            a = a +1
        end
end

I now get an error like this:

[no implicit conversion of String into Integer]

How can I solve this?

1

1 Answer 1

2

You need just select for that:

p hash.select { |_, value| value['partition'] == 'baas' }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.