Class: String
Instance Method Summary collapse
-
#in_groups_of(size) ⇒ Object
Returns an array of the string broken down into groups of
size
characters.
Instance Method Details
#in_groups_of(size) ⇒ Object
Returns an array of the string broken down into groups of size
characters.
"aabbcc".in_groups_of(2)
#=> ['aa', 'bb', 'cc']
"".in_groups_of(2)
#=> []
"".in_groups_of(0)
#=> ArgumentError
10 11 12 13 |
# File 'lib/shenanigans/string/in_groups_of.rb', line 10 def in_groups_of(size) raise ArgumentError, "Size of group must be >= 1" if size < 1 scan(/.{1,#{size}}/) end |