Module: Xqsr3::StringUtilities::StartsWith::StartsWith_Helper_
- Defined in:
- lib/xqsr3/string_utilities/starts_with.rb
Overview
:nodoc:
Class Method Summary collapse
Class Method Details
.string_starts_with_array_(s, args) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/xqsr3/string_utilities/starts_with.rb', line 81 def self.string_starts_with_array_ s, args return '' if args.empty? args.each do |prefix| case prefix when ::NilClass return '' when ::String r = self.string_starts_with_helper_ s, prefix return r if r else if prefix.respond_to? :to_str return self.string_starts_with_helper_ s.prefix.to_str end raise TypeError, "starts_with? can be passed instances of #{::String}, or nil, or types that respond to to_str" end end return nil end |
.string_starts_with_helper_(s, prefix) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/xqsr3/string_utilities/starts_with.rb', line 62 def self.string_starts_with_helper_ s, prefix if prefix.nil? || prefix.empty? return '' elsif prefix.size < s.size return prefix if s[0 ... prefix.size] == prefix elsif prefix.size == s.size return prefix if prefix == s else nil end nil end |