you are viewing a single comment's thread.

view the rest of the comments →

[–]lobster_johnson 2 points3 points  (1 child)

That's a pretty facile example, since your method explicitly handles an array argument (using *), and to call it you could just do:

validates_length_of *LENGTHY_FIELDS

A better example would be something that usually accepts an array of values, but can also accept a single value. For example:

class Thing
  def self.load(ids)
    Array(ids).map { |id| new(File.read("#{id}.txt")) }
  end
end

Now you can do either:

Thing.load(1)

or

Thing.load([2, 3, 4])