Sha256: b9168ec7d7cf99065f47251f5497fc8f1c9a852c1b4b1069f348f561e4c4ef62
Contents?: true
Size: 810 Bytes
Versions: 3
Compression:
Stored size: 810 Bytes
Contents
require_relative '../y_support' # RespondTo class for easy use of respond_to? in case statements. # class RespondTo Matchers = {} attr_reader :method def self.create method; Matchers[ method ] ||= new method end def initialize method; @method = method end def === obj; obj.respond_to? method end end class Object # RespondTo constructor. # def RespondTo method; RespondTo.create method end end class Symbol # Creates a RespondTo object from the receiver symbol. Intended use for this # is nin case statements: RespondTo has customized #=== method, that calls # #respond_to? to determine the return value. # # For example, <tt>when ~:each</tt> in a case statement is valid only if the # tested object respond_to?( :each ) returns true. # def ~@; RespondTo self end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
y_support-2.4.6 | lib/y_support/respond_to.rb |
y_support-2.4.5 | lib/y_support/respond_to.rb |
y_support-2.4.4 | lib/y_support/respond_to.rb |