Sha256: 8a7146e9b6cfbef8fa1de87c35f6ae71d21085100290c4215896a48b6bb33e5e

Contents?: true

Size: 1.15 KB

Versions: 26

Compression:

Stored size: 1.15 KB

Contents

# coding: utf-8
#
# Why would we ever use Ruby 1.8.7 when we can backport with something
# as simple as this?
#
# copied from prawn.
# modified by Hideo NAKAMURA
#
class String #:nodoc:
  def first_line
    self.each_line { |line| return line }
  end
  unless "".respond_to?(:lines)
    alias_method :lines, :to_a
  end
  unless "".respond_to?(:each_char)
    def each_char #:nodoc:
      # copied from jcode
      if block_given?
        scan(/./m) { |x| yield x }
      else
        scan(/./m)
      end
    end
  end

  unless "".respond_to?(:bytesize)
    def bytesize # :nodoc:
      self.length
    end
  end

  unless "".respond_to?(:ord)
    def ord
      self[0]
    end
  end

  unless "".respond_to?(:ascii_only?)
    def ascii_only?
      !!(self =~ /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]\{\}^` ~\0\n]/)
    end
  end
end

unless File.respond_to?(:binread)
  def File.binread(file) #:nodoc:
    File.open(file,"rb:utf-8:utf-8") { |f| f.read }
  end
end

if RUBY_VERSION < "1.9"

  def ruby_18 #:nodoc:
    yield
  end

  def ruby_19 #:nodoc:
    false
  end

else

  def ruby_18 #:nodoc:
    false
  end

  def ruby_19 #:nodoc:
    yield
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
write_xlsx-1.09.4 lib/write_xlsx/compatibility.rb
write_xlsx-1.09.3 lib/write_xlsx/compatibility.rb
write_xlsx-1.09.2 lib/write_xlsx/compatibility.rb
write_xlsx-1.09.1 lib/write_xlsx/compatibility.rb
write_xlsx-1.09.0 lib/write_xlsx/compatibility.rb
write_xlsx-1.08.2 lib/write_xlsx/compatibility.rb
write_xlsx-1.08.1 lib/write_xlsx/compatibility.rb
write_xlsx-1.08.0 lib/write_xlsx/compatibility.rb
write_xlsx-1.07.0 lib/write_xlsx/compatibility.rb
write_xlsx-1.04.0 lib/write_xlsx/compatibility.rb
write_xlsx-1.02.0 lib/write_xlsx/compatibility.rb
write_xlsx-1.01.0 lib/write_xlsx/compatibility.rb
write_xlsx-1.00.0 lib/write_xlsx/compatibility.rb
write_xlsx-0.99.0 lib/write_xlsx/compatibility.rb
write_xlsx-0.97.0 lib/write_xlsx/compatibility.rb
write_xlsx-0.90.0 lib/write_xlsx/compatibility.rb
write_xlsx-0.89.0 lib/write_xlsx/compatibility.rb
write_xlsx-0.88.0 lib/write_xlsx/compatibility.rb
write_xlsx-0.87.0 lib/write_xlsx/compatibility.rb
write_xlsx-0.86.0 lib/write_xlsx/compatibility.rb