Getting parent relationship I am trying to find the best way to structure this. I want to avoid if-else statements and reduce the number of code lines.

def get_parent(relationships,GU)
  parent = []
  if relationships.class == Array
    relationships.each do |y|
      if y[:relationship_roles][:relationship_role][:to_role][:name] == type
        parent &lt;&lt; y[:party][:party_id][:id]
      end
    end
  else
    if relationships[:relationship_roles][:relationship_role][:to_role][:name] == type
      parent &lt;&lt; relationships[:party][:party_id][:id]
    end
  end
  return parent
end


Input:

:relationship=&gt;{:name=&gt;nil, :party=&gt;{:party_id=&gt;{:id=&gt;"12344", 
:id_type=&gt;"abc"}, :name=&gt;"XYZ", :@active=&gt;"true", :@type=&gt;"Organization"}, 
:relationship_roles=&gt;{:relationship_role=&gt;{:to_role=&gt;{:name=&gt;"GU"}}}}


The input could be only one relationship or multiple ones, which is why I have the if/else loop.
Some notes:


It would be debatable whether it's good practice to have arguments which may contain either single elements or collections. 
If you convert whatever you get to an array (using Array), there is no need to repeat code.
Don't use each + &lt;&lt; (imperative), use map + compact (functional).


I'd write:

def get_parent(relationship_item_or_collection)
  Array(relationship_item_or_collection).map do |relationship|
    if relationship[:relationship_roles][:relationship_role][:to_role][:name] == type
      relationship[:party][:party_id][:id]
    end
  end.compact
end