Sha256: 76d0829acca211232b1be0685f0720355ca782940a08870bdb4cd4334178ddf0

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

unless :to_proc.respond_to?(:to_proc)
  class Symbol
    # Turns the symbol into a simple proc, 
    # which is especially useful for enumerations.
    # Extracted from ActiveSupport.
    #
    # Examples
    #
    #   # The same as people.collect { |p| p.name }
    #   people.collect(&:name)
    #
    #   # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
    #   people.select(&:manager?).collect(&:salary)
    #
    # Returns a Proc which incapsulates the method business logic.
    def to_proc
      Proc.new { |*args| args.shift.__send__(self, *args) }
    end
  end
end


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
    # Extracted from ActiveSupport.
    #
    # 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.
    def to_time
      self.offset == 0 ? ::Time.utc(year, month, day, hour, min, sec) : self
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
whois-1.2.2 lib/core_ext.rb
whois-1.2.1 lib/core_ext.rb
whois-1.2.0 lib/core_ext.rb
whois-1.1.8 lib/core_ext.rb
whois-1.1.7 lib/core_ext.rb