Sha256: 403a8b32f83d2e609f7186bf87befce6da747d920e835071fd2c46421cc27206

Contents?: true

Size: 1.42 KB

Versions: 17

Compression:

Stored size: 1.42 KB

Contents

class String
  class << self
    # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
    def try_convert(x)
      return nil unless x.respond_do(:to_str)
      x.to_str
    end unless method_defined? :try_convert
  end

  # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
  def ascii_only?
    !(self =~ /[^\x00-\x7f]/)
  end unless method_defined? :ascii_only?

  # Standard in Ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
  def clear
    self[0,length] = ""
    self
  end unless method_defined? :clear

  # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
  def codepoints
    return to_enum(:codepoints) unless block_given?
    each_char.each do |s|
      utf8 = s.each_byte.to_a
      utf8[0] &= 0xff >> utf8.size # clear high bits (1 to 4, depending of number of bytes used)
      yield utf8.inject{|result, b| (result << 6) + (b & 0x3f) }
    end
  end unless method_defined? :codepoints
  
  # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
  alias_method :each_codepoint, :codepoints unless method_defined? :each_codepoint

  # Standard in Ruby 1.9. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html]
  def getbyte(i)
    self[i]
  end unless method_defined? :getbyte
  
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
marcandre-backports-1.8.0 lib/backports/1.9/string.rb
marcandre-backports-1.8.1 lib/backports/1.9/string.rb
marcandre-backports-1.8.2 lib/backports/1.9/string.rb
marcandre-backports-1.8.3 lib/backports/1.9/string.rb
marcandre-backports-1.8.4 lib/backports/1.9/string.rb
marcandre-backports-1.9.0 lib/backports/1.9/string.rb
backports-1.11.0 lib/backports/1.9/string.rb
backports-1.10.3 lib/backports/1.9/string.rb
backports-1.10.2 lib/backports/1.9/string.rb
backports-1.10.1 lib/backports/1.9/string.rb
backports-1.10.0 lib/backports/1.9/string.rb
backports-1.8.3 lib/backports/1.9/string.rb
backports-1.9.0 lib/backports/1.9/string.rb
backports-1.8.4 lib/backports/1.9/string.rb
backports-1.8.0 lib/backports/1.9/string.rb
backports-1.8.2 lib/backports/1.9/string.rb
backports-1.8.1 lib/backports/1.9/string.rb