Sha256: 86bc59aec8c932659753f0dd14026cb52f508cc24f55681c381106ad9d23e19d

Contents?: true

Size: 842 Bytes

Versions: 1

Compression:

Stored size: 842 Bytes

Contents

require 'naught'

module Twitter
  NullObject = Naught.build do |config|
    include Comparable

    config.black_hole
    config.define_explicit_conversions
    config.define_implicit_conversions
    config.predicates_return false

    # TODO: Add when support for Ruby 1.8.7 is dropped
    # def !
    #   true
    # end

    def respond_to?(*)
      true
    end

    def instance_of?(klass)
      fail(TypeError.new('class or module required')) unless klass.is_a?(Class)
      self.class == klass
    end

    def kind_of?(mod)
      fail(TypeError.new('class or module required')) unless mod.is_a?(Module)
      self.class.ancestors.include?(mod)
    end

    alias_method :is_a?, :kind_of?

    def <=>(other)
      if other.is_a?(self.class)
        0
      else
        -1
      end
    end

    def nil?
      true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twitter-5.14.0 lib/twitter/null_object.rb