Convert ruby source code from old style to new style hash Convert ruby source code from old style to new style hash ruby ruby

Convert ruby source code from old style to new style hash


Rubocop is a static code analyzer that evaluates your code against many of the recommendations of the Ruby Style Guide. It has an --auto-correct option that can automatically change your code to what is recommended. One of those auto-correct options is for hash syntax.

Example:

rubocop --only HashSyntax --auto-correct

will only correct your hashes.


The gem hash_syntax is capable of converting from the old style hash to the new style hash, or vice versa.

Once you've installed the gem, you just have to do in the project's root directory

hash_syntax --to-19

to convert from old to new, or

hash_syntax --to-18

to convert from new to old.


I did with the hash_syntax gem with following commands:

gem install hash_syntaxhash_syntax --to-19 lib/foo.rb