Sha256: c737dbc5448243dee6ac6acc5ed1e8ac4ed3672151bdb6ff87ab2be73e0a45d9

Contents?: true

Size: 1.23 KB

Versions: 113

Compression:

Stored size: 1.23 KB

Contents

class Array
  def select! # :yield: x
    i = 0
    each_with_index { |x, j|
      yield x or next
      self[i] = x if i != j
      i += 1
    }
    return nil if i == size
    self[i..-1] = []
    self
  end unless method_defined?(:select!)

  def sort_by!(&block) # :yield: x
    replace(sort_by(&block))
  end unless method_defined?(:sort_by!)
end

class Hash
  class << self
    def try_convert(object)
      if object.is_a?(Hash) ||
          (object.respond_to?(:to_hash) && (object = object.to_hash).is_a?(Hash))
        object
      else
        nil
      end
    end unless method_defined?(:try_convert)
  end
end

class String
  class << self
    def try_convert(object)
      if object.is_a?(String) ||
          (object.respond_to?(:to_str) && (object = object.to_str).is_a?(String))
        object
      else
        nil
      end
    end unless method_defined?(:try_convert)
  end
end

# In Ruby < 1.9.3 URI() does not accept a URI object.
if RUBY_VERSION < "1.9.3"
  require 'uri'

  begin
    URI(URI(''))
  rescue
    def URI(url) # :nodoc:
      case url
      when URI
        url
      when String
        URI.parse(url)
      else
        raise ArgumentError, 'bad argument (expected URI object or URI string)'
      end
    end
  end
end

Version data entries

113 entries across 86 versions & 14 rubygems

Version Path
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
suzuko-0.1.8 vendor/bundle/ruby/2.0.0/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
suzuko-0.1.7 vendor/bundle/ruby/2.0.0/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/http-cookie-1.0.2/lib/http/cookie/ruby_compat.rb
http-cookie-1.0.2 lib/http/cookie/ruby_compat.rb
http-cookie-1.0.1 lib/http/cookie/ruby_compat.rb
http-cookie-1.0.0 lib/http/cookie/ruby_compat.rb