Last Updated: February 25, 2016
·
239
· aceofspades

Coding conventions: Use 'z' as suffix for identifiers that could be singular or parallel

Something simple to do in your code that might otherwise require explanation or comments.

If a method accepts an argument which could either be a single element or array, use 'z' as a suffix, rather than the singular or plural name. This calls immediate attention that something is different, and once learned, is pretty clear on sight.

def add_itemz(itemz)
  Array(itemz).each do |item|
    # ...
  end
end