File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -794,11 +794,45 @@ in *Ruby* now, not in *Python*.
794794* It ' s ok to use arrays as sets for a small number of elements.
795795* Prefer `%w` to the literal array syntax when you need an array of
796796strings.
797+
798+ ```Ruby
799+ # bad
800+ STATES = [' draft' , ' open ' , ' closed' ]
801+
802+ # good
803+ STATES = %w(draft open closed)
804+ ```
805+
797806* Avoid the creation of huge gaps in arrays.
807+
808+ ```Ruby
809+ arr = []
810+ arr[100] = 1 # now you have an array with lots of nils
811+ ```
812+
798813* Use `Set` instead of `Array` when dealing with lots of elements.
799814* Use symbols instead of strings as hash keys.
815+
816+ ```Ruby
817+ # bad
818+ hash = { ' one' => 1, ' two' => 2, ' three' => 3 }
819+
820+ # good
821+ hash = { one: 1, two: 2, three: 3 }
822+ ```
823+
800824* Avoid the use of mutable object as hash keys.
801- * Use the new 1.9 literal hash syntax in preference to the hashrocket syntax.
825+ * Use the new 1.9 literal hash syntax in preference to the hashrocket
826+ syntax.
827+
828+ ```Ruby
829+ # bad
830+ hash = { :one => 1, :two => 2, :three => 3 }
831+
832+ # good
833+ hash = { one: 1, two: 2, three: 3 }
834+ ```
835+
802836* Rely on the fact that hashes in 1.9 are ordered.
803837* Never modify a collection while traversing it.
804838
You can’t perform that action at this time.
0 commit comments