Using constructor methods like Array.new
and Hash.new
without parameters is unnecessarily verbose compared to the literal
syntax []
and {}
. The literal syntax is more concise, widely recognized as idiomatic Ruby, and preferred by the Ruby
community.
Literal syntax makes the code more readable and consistent with Ruby conventions. When no parameters are needed, the constructor methods provide no
additional functionality over literals, making them redundant.
This pattern is particularly important in Ruby codebases where consistency and readability are valued. Most Ruby style guides, including those from
major organizations, recommend using literal syntax for empty collections.
What is the potential impact?
This issue affects code readability and maintainability. While it doesn’t impact functionality, inconsistent style can make code harder to read and
maintain, especially in team environments where coding standards matter.