This cop checks hash literal syntax.
It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).
A separate offense is registered for each problematic pair.
# File lib/rubocop/cop/style/hash_syntax.rb, line 35 def autocorrect(node) key = node.children.first.loc.expression op = node.loc.operator @corrections << lambda do |corrector| if style == :ruby19 range = Parser::Source::Range.new(key.source_buffer, key.begin_pos, op.end_pos) range = range_with_surrounding_space(range, :right) corrector.replace(range, range.source.sub(/^:(.*\S)\s*=>\s*$/, '\1: ')) else corrector.insert_after(key, ' => ') corrector.insert_before(key, ':') corrector.remove(range_with_surrounding_space(op)) end end end
# File lib/rubocop/cop/style/hash_syntax.rb, line 29 def hash_rockets_check(node) pairs = *node check(pairs, ':', MSG_HASH_ROCKETS) end
Generated with the Darkfish Rdoc Generator 2.