To return a value from a loop, use break value
:
def my_def(port)
@hsh.each do |k, v|
break k if v == port
end
end
In general, @Stefan’s comment solves this particular problem better:
def my_def port
@hsh.key port
end
solved return value from loop