Sha256: ba587300ca724f9bf5353523e34fafeb2133aa305ebd2cac8fc9f4b17a9aa09f

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

require 'date'

class DateTime

  # Don't remove method if exists or it will conflict with ActiveRecord.
  # See http://github.com/weppos/whois/issues#issue/24
  unless method_defined?(:to_time)
    # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class
    # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time.
    #
    # Extracted from ActiveSupport.
    def to_time
      self.offset == 0 ? ::Time.utc(year, month, day, hour, min, sec) : self
    end
  end

end


class Array

  # Wraps its argument in an array unless it is already an array (or array-like).
  #
  # Specifically:
  #
  # * If the argument is +nil+ an empty list is returned.
  # * Otherwise, if the argument responds to +to_ary+ it is invoked, and its result returned.
  # * Otherwise, returns an array with the argument as its single element.
  #
  #   Array.wrap(nil)       # => []
  #   Array.wrap([1, 2, 3]) # => [1, 2, 3]
  #   Array.wrap(0)         # => [0]
  #
  # Extracted from ActiveSupport.
  def self.wrap(object)
    if object.nil?
      []
    elsif object.respond_to?(:to_ary)
      object.to_ary
    else
      [object]
    end
  end unless respond_to?(:wrap)

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
whois-2.0.7 lib/core_ext.rb
whois-2.0.6 lib/core_ext.rb
whois-2.0.5 lib/core_ext.rb
whois-2.0.4 lib/core_ext.rb
whois-2.0.3 lib/core_ext.rb
whois-2.0.2 lib/core_ext.rb
whois-2.0.1 lib/core_ext.rb
whois-2.0.0 lib/core_ext.rb