I have the following OpenStruct data structure, I'm trying to get key/value pair
> #<OpenStruct conditions=[#<OpenStruct field="Out_of_country", operator="us", values=["true"]>, #<OpenStruct field="Status__c",
> operator="jp", values=["'Approved'"]>, #<OpenStruct field="Status__c",
> operator="gb", values=["'Rejected'"]>], conjunction="and">
Ruby code:
dataResult = nil
dataResult = data['condition'].include?('out_of_country']
is that how you extract key/value pair from OpenStruct?
UPDATE:
you're right I was using the to_s and I remove and here is what I'm trying to access the key/value
myresult = data['mainCondtion']
p myresult --> I got this result:
> #<OpenStruct conditions=[#<OpenStruct field="Out_of_country", operator="us", values=["true"]>, #<OpenStruct field="Status__c",
> operator="jp", values=["'Approved'"]>, #<OpenStruct field="Status__c",
> operator="gb", values=["'Rejected'"]>], conjunction="and">
then I try to access field and values
myresult.each_pair{ |key, value| puts "#{key}: #{value}" }
I get this error:
undefined method "each_pair" for #
You are trying to loop over an array of hashes.
See this example answer on SO - How do I iterate over an array of hashes and return the values in a single string?
@max didn't like that I didn't post a long-form explanation, so I'm going to expand on my above answer.
Both OpenStructs and Hashes respond to the method that @max recommends - making them no different functionally in the case that you are describing.
There is no functional difference.