Created
December 15, 2015 16:18
-
-
Save TheKidCoder/402b7e77aae48a3da34d 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
class Thinger | |
def run! | |
[:first_thing, :second_thing, :third_thing].map do |meth_name| | |
begin | |
self.method(meth_name).call | |
rescue => e | |
puts "There was a problem running: #{meth_name}" | |
next | |
end | |
end | |
end | |
def first_thing | |
puts "I'm the first to go!" | |
end | |
def second_thing | |
raise StandardError, "Oh no!" | |
end | |
def third_thing | |
puts "Last to finish!" | |
end | |
end |
- It's a bang method because it's a stylistic choice that I use when I don't have an explicit return value. In this case, I would usually return true/false here.
- It's hard coded because this can be seen more as a service object. I don't really understand this question anyway, at some point in the code, there will be a hard-coded list.
- I dislike
send
. If anything,public_send
is better and using this method you can do other things, (maybe a conditional on the arity of the method). - I'm not in the implicit return camp. Likewise, I like to be explicit about what an iterator is doing when catching an error. Just stylistic.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I.e. you could just do something like