Sha256: 6a193db16e01ced9a8849e9999d63a87453fa7d258c6b4806831b6d5e6b7aa36
Contents?: true
Size: 1.21 KB
Versions: 22
Compression:
Stored size: 1.21 KB
Contents
class String class << self # Standard in Ruby 1.8.8. 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.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html] Backports.alias_method self, :getbyte, :[] # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html] Backports.alias_method self, :setbyte, :[]= # Let's define this here, we can use it for ord: unless method_defined? :codepoints def codepoints return to_enum(:codepoints) unless block_given? each_char 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 private :codepoints # Will be made available in 1.9.1/string.rb, if included end # Standard in Ruby 1.8.8. See official documentation[http://ruby-doc.org/core-1.9/classes/String.html] def ord codepoints.first end unless method_defined? :ord end
Version data entries
22 entries across 22 versions & 1 rubygems