This cop checks for the use of a method, the result of which would be a literal, like an empty array, hash or string.
# File lib/rubocop/cop/style/empty_literal.rb, line 46 def autocorrect(node) @corrections << lambda do |corrector| name = case node when ARRAY_NODE then '[]' when HASH_NODE then '{}' when STR_NODE then "''" end corrector.replace(node.loc.expression, name) end end
# File lib/rubocop/cop/style/empty_literal.rb, line 30 def on_send(node) return if part_of_ignored_node?(node) case node when ARRAY_NODE add_offense(node, :expression, ARR_MSG) when HASH_NODE add_offense(node, :expression, HASH_MSG) when STR_NODE add_offense(node, :expression, STR_MSG) end end
Generated with the Darkfish Rdoc Generator 2.