STYLEGUIDE.md in rubocop-github-0.9.0 vs STYLEGUIDE.md in rubocop-github-0.9.1

- old
+ new

@@ -222,9 +222,34 @@ def multiplex(text, count) text * count end ``` +## Dynamic Dispatch + +Avoid calling `send` and its cousins unless you really need it. Metaprogramming can be extremely powerful, but in most cases you can write code that captures your meaning by being explicit: + +``` ruby +# avoid +unless [:base, :head].include?(base_or_head) + raise ArgumentError, "base_or_head must be either :base or :head" +end + +repository = pull.send("#{base_or_head}_repository") +branch = pull.send("#{base_or_head}_ref_name") + +# prefer +case base_or_head +when :base + repository = pull.base_repository + branch = pull.base_ref_name +when :head + repository = pull.head_repository + branch = pull.head_ref_name +else + raise ArgumentError, "base_or_head must be either :base or :head" +end +``` ## Exceptions * Don't use exceptions for flow of control. ``` ruby