Created
June 27, 2011 07:51
-
-
Save denysonique/1048460 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
begin | |
variable = x.some_method.hax | |
rescue | |
variable = x.some_method.foo | |
rescue | |
variable = x.some_method.bar | |
end | |
#I would like to acheive something similar to: | |
variable = x.some_method.hax | |
variable ||= x.some_method.foo | |
variable ||= x.some_method.bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
variable = x.try(:some_method).try(:hax)
variable ||= x.try(:some_method).try(:foo)
variable ||= x.try(:some_method).try(:bar)
or:
variable = x.some_method.hax rescue nil
variable ||= x.some_method.foo rescue nil
variable ||= x.some_method.bar