In Ruby 2.0+, nil.to_h
is { }
; also, nil.to_a
has been [ ]
as long as I can remember. Of course, if h
is a Hash then h.to_h
is h
and if a
is an Array then a.to_a
is a
. You can use this to hide nil
s thusly:
value = ary.find {|r| r["rail"][0] == lookup_rail}.to_h["id"].to_a[0]