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
-
#j_ci_fetch(somestring) ⇒ String?
Fetch a string from an Array case-insensitively, e.g.
-
#j_ci_include?(somestring) ⇒ Boolean
case-insensitive version of include?.
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
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?
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 |