Class: String

Inherits:
Object show all
Defined in:
lib/shenanigans/string/cmpi.rb,
lib/shenanigans/string/in_groups_of.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) cmpi(other)

Compares strings ignoring case

"test".cmpi("tesT")
#=> true


5
6
7
# File 'lib/shenanigans/string/cmpi.rb', line 5

def cmpi(other)
  self.casecmp(other).zero?
end

- (Object) in_groups_of(size)

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

Raises:

  • (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