File: start_with.rb

package info (click to toggle)
ruby-backports 3.25.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,912 kB
  • sloc: ruby: 11,759; makefile: 6
file content (12 lines) | stat: -rw-r--r-- 275 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
unless String.method_defined? :start_with?
  class String
    def start_with?(*prefixes)
      prefixes.any? do |prefix|
        if prefix.respond_to? :to_str
          prefix = prefix.to_str
          self[0, prefix.length] == prefix
        end
      end
    end
  end
end