Class: String
- Defined in:
- lib/shenanigans/string/cmpi.rb,
lib/shenanigans/string/in_groups_of.rb
Instance Method Summary collapse
-
#cmpi(other) ⇒ Object
Compares strings ignoring case.
-
#in_groups_of(size) ⇒ Object
Returns an array of the string broken down into groups of
size
characters.
Instance Method Details
#cmpi(other) ⇒ Object
Compares strings ignoring case
6 7 8 |
# File 'lib/shenanigans/string/cmpi.rb', line 6 def cmpi(other) casecmp(other).zero? end |
#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
7 8 9 10 11 |
# File 'lib/shenanigans/string/in_groups_of.rb', line 7 def in_groups_of(size) raise ArgumentError, "Size of group must be >= 1" if size < 1 scan(/.{1,#{size}}/) end |