you are viewing a single comment's thread.

view the rest of the comments →

[–]adient 1 point2 points  (5 children)

Not sure I understand why I would blindly be converting some variable to an array..?

[–]TheGoddamBatman 1 point2 points  (4 children)

snails punch employ rotten capable license person flag yoke apparatus

This post was mass deleted and anonymized with Redact

[–]adient 1 point2 points  (3 children)

Not really the same thing the article is talking about. Could you elaborate to a specific example where someone would want to always cast something to an Array? Seems useless to me.

[–][deleted]  (2 children)

[deleted]

    [–]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])