Module: JamfRubyExtensions::Array::Utils

Included in:
Array
Defined in:
lib/jamf/ruby_extensions/array/utils.rb

Overview

Useful monkey patches for Array

Instance Method Summary collapse

Instance Method Details

#j_ci_fetch(somestring) ⇒ String?

Fetch a string from an Array case-insensitively, e.g. if my_array contains 'thrasher',

my_array.j_ci_fetch('ThRashEr')

will return 'thrasher'

returns nil if no match

Parameters:

  • somestring (String)

    the String to search for

Returns:

  • (String, nil)

    The matching string as it exists in the Array, nil if it doesn't exist



43
44
45
46
# File 'lib/jamf/ruby_extensions/array/utils.rb', line 43

def j_ci_fetch(somestring)
  each { |s| return s if s.respond_to?(:casecmp?) && s.casecmp?(somestring) }
  nil
end

#j_ci_include?(somestring) ⇒ Boolean

case-insensitive version of include?

Parameters:

  • somestring (String)

    the String to search for

Returns:

  • (Boolean)


54
55
56
# File 'lib/jamf/ruby_extensions/array/utils.rb', line 54

def j_ci_include?(somestring)
  any? { |s| s.respond_to?(:casecmp?) && s.casecmp?(somestring) }
end