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? Also known as: jss_ci_fetch_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