Method: Array#jss_ci_fetch_string

Defined in:
lib/jss/ruby_extensions/array.rb

#jss_ci_fetch_string(somestring) ⇒ String?

Fetch a string from an Array of Strings case-insensitively, e.g. my_array.jss_ci_fetch_string(‘ThRashEer’) will return ‘thrasher’ or 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



47
48
49
50
# File 'lib/jss/ruby_extensions/array.rb', line 47

def jss_ci_fetch_string(somestring)
  idx = index { |s| s.to_s.casecmp(somestring).zero? }
  idx ? self[idx] : nil
end