Sha256: 074cf56553251263114bb75310b76fa08e490e49663a10c5d501cfacff419da3

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

module Kernel
  def ruby_19?; (RUBY_VERSION >= "1.9"); end
end

if RUBY_VERSION < "1.9"
  class String
    # DON'T USE String#each. Use String#each_line
    def lines
      self.split("\n").each do |l|
        yield l
      end
    end
    
    ##
    # Returns the numeric, ascii value of the first character
    # in the string.
    #
    # @return [Fixnum] the ascii value of the first character in the string
    def ord
      self[0]
    end
  end
  class Object
    def tap
      yield self
      self
    end
  end
else
  # 1.9 +
  # Autoload bug in 1.9 means we have to directly require these. FML.
  require 'continuation'
  require 'zlib'
  require 'stringio'
  require 'fileutils'
  class String
    # String doesn't include Enumerable in Ruby 1.9, so we lose #any?.
    # Luckily it's quite easy to implement.
    #
    # @return [Boolean] does the string have anything in it?
    def any?
      size > 0
    end
  end
  
  class File
    ##
    # This is in ftools in Ruby 1.8.x, but now it's in FileUtils. So
    # this is essentially an alias to it. Silly ftools, trix are for kids.
    def self.copy(*args)
      FileUtils.copy(*args)
    end
    ##
    # This is in ftools in Ruby 1.8.x, but now it's in FileUtils. So
    # this is essentially an alias to it. Silly ftools, trix are for kids.
    def self.move(*args)
      FileUtils.move(*args)
    end
    ##
    # This is in ftools in Ruby 1.8.x, but now it's in FileUtils. So
    # this is essentially an alias to it. Silly ftools, trix are for kids.
    def self.makedirs(*args)
      FileUtils.makedirs(*args)
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
amp-pure-0.5.0 lib/amp/support/ruby_19_compatibility.rb
amp-0.5.0 lib/amp/support/ruby_19_compatibility.rb