Class: Array

Inherits:
Object show all
Defined in:
lib/jss/compatibility.rb,
lib/jss/ruby_extensions/array.rb

Instance Method Summary collapse

Instance Method Details

#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

#jss_ci_include_string?(somestring) ⇒ Boolean

A case-insensitive version of #include? for Arrays of Strings.

Parameters:

  • somestring (String)

    the String to search for

Returns:

  • (Boolean)

    Does the Array contain the String, ignoring case?


35
36
37
# File 'lib/jss/ruby_extensions/array.rb', line 35

def jss_ci_include_string?(somestring)
  any? { |s| s.to_s.casecmp(somestring).zero? }
end