From: "Jesús Gabriel y Galán" Date: 2008-10-21T17:33:41+09:00 Subject: Re: Can anyone tell me why my code isn't working? On Tue, Oct 21, 2008 at 9:59 AM, Brian Candler wrote: > You could fix this by changin "return res" to "return res if v == 3", or > "return res if res", but more simply > > def mycode > (1..5).each do |v| > return v if v == 3 > end > end > puts mycode # 3 Also check Enumerable#find: irb(main):002:0> a = [{:name => "a", :value => 3}, {:name => "b", :value => 4}, {:name => "c", :value => 10}] => [{:value=>3, :name=>"a"}, {:value=>4, :name=>"b"}, {:value=>10, :name=>"c"}] irb(main):003:0> a.find {|s| s[:name] == "b"} => {:value=>4, :name=>"b"} So, you method could be done as: def get_mac_by_host(host_name) s = @plist_hash['servers'].find {|s| s['name'] == host_name} return s['mac'] if s nil end (not tested). Hope this helps, Jesus.