Created
October 20, 2014 20:39
-
-
Save justincampbell/7c7531b42b847a18b3f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Return nested hash element, or nil if hash structure does not match | |
# no checking | |
def find_third(id) | |
input = find_input(id) | |
input['first']['second']['third'] | |
end | |
# begin/rescue/end | |
def find_third(id) | |
input = find_input(id) | |
begin | |
input['first']['second']['third'] | |
rescue | |
end | |
end | |
# rescue nil | |
def find_third(id) | |
input = find_input(id) | |
input['first']['second']['third'] rescue nil | |
end | |
# return unless | |
def find_third(id) | |
input = find_input(id) | |
first = input['first'] | |
return unless first | |
second = first['second'] | |
return unless second | |
second['third'] | |
end | |
# && | |
def find_third(id) | |
input = find_input(id) | |
return unless input['first'] && | |
input['first']['second'] && | |
input['first']['second']['third'] | |
input['first']['second']['third'] | |
end | |
# andand gem | |
def find_third(id) | |
input = find_input(id) | |
input['first'].andand['second'].andand['third'] | |
end | |
# vine gem | |
def find_third(id) | |
input = find_input(id) | |
input.access('first.second.third') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment