module Polyfill::V2_4::String

Public Instance Methods

casecmp?(other) click to toggle source
# File lib/polyfill/v2_4/string.rb, line 15
def casecmp?(other)
  casecmp(InternalUtils.to_str(other)) == 0
end
concat(*others) click to toggle source
Calls superclass method
# File lib/polyfill/v2_4/string.rb, line 19
def concat(*others)
  return super if others.length == 1

  acc = '' << self
  others.each do |other|
    acc << other
  end

  replace(acc)
end
each_line(*args) { |chomp| ... } click to toggle source
Calls superclass method
# File lib/polyfill/v2_4/string.rb, line 30
def each_line(*args)
  hash, others = args.partition { |arg| arg.is_a?(::Hash) }
  chomps = hash[0] && hash[0][:chomp]

  unless block_given?
    return super(*others) unless chomps

    separator = others.find do |other|
      other.respond_to?(:to_str)
    end || $INPUT_RECORD_SEPARATOR
    return ::Enumerator.new do |yielder|
      super(*others) do |line|
        yielder.yield(line.chomp(separator))
      end
    end
  end

  block =
    if chomps
      separator = others.find do |other|
        other.respond_to?(:to_str)
      end || $INPUT_RECORD_SEPARATOR

      proc do |line|
        yield(line.chomp(separator))
      end
    else
      ::Proc.new
    end

  super(*others, &block)
end
lines(*args) { |chomp| ... } click to toggle source
Calls superclass method
# File lib/polyfill/v2_4/string.rb, line 63
def lines(*args)
  hash, others = args.partition { |arg| arg.is_a?(::Hash) }
  chomps = hash[0] && hash[0][:chomp]

  unless block_given?
    lines = super(*others)

    if chomps
      separator = others.find do |other|
        other.respond_to?(:to_str)
      end || $INPUT_RECORD_SEPARATOR

      lines.each { |line| line.chomp!(separator) }
    end

    return lines
  end

  block =
    if chomps
      separator = others.find do |other|
        other.respond_to?(:to_str)
      end || $INPUT_RECORD_SEPARATOR

      proc do |line|
        yield(line.chomp(separator))
      end
    else
      ::Proc.new
    end

  super(*others, &block)
end
match?(pattern, position = 0) click to toggle source
# File lib/polyfill/v2_4/string.rb, line 97
def match?(pattern, position = 0)
  !!(self[position..-1] =~ pattern)
end
prepend(*others) click to toggle source
Calls superclass method
# File lib/polyfill/v2_4/string.rb, line 101
def prepend(*others)
  return super if others.length == 1

  acc = '' << self
  others.reverse_each do |other|
    acc.prepend(other)
  end

  replace(acc)
end
unpack1(*args) click to toggle source
# File lib/polyfill/v2_4/string.rb, line 112
def unpack1(*args)
  unpack(*args).first
end