Class: Filigree::InstancePattern

Inherits:
SingleObjectPattern show all
Defined in:
lib/filigree/match.rb

Overview

A pattern for checking to see if an object is an instance of a given class.

Instance Attribute Summary

Attributes inherited from SingleObjectPattern

#pattern_elem

Instance Method Summary collapse

Methods inherited from SingleObjectPattern

#initialize

Methods included from AbstractClass

#abstract_method, extended, #install_icvars, #new

Methods inherited from BasicPattern

#as

Constructor Details

This class inherits a constructor from Filigree::SingleObjectPattern

Instance Method Details

#<=>(other) ⇒ -1, ...

Specialized version of the bi-directional comparison operator.

Parameters:

  • other (BasicPattern)

    Right-hand side of the comparison

Returns:

  • (-1, 0, 1)

    Value corresponding to less than, equal to, or greater than the right-hand side pattern.



359
360
361
362
363
364
365
366
367
368
# File 'lib/filigree/match.rb', line 359

def <=>(other)
	if other.is_a?(InstancePattern)
		if    self.pattern_elem == other.pattern_elem            then 0
		elsif self.pattern_elem.subclass_of?(other.pattern_elem) then 1
		else                                                         -1
		end
	else
		super(other)
	end
end

#match?(object, _) ⇒ Boolean

Test the object to see if the object is an instance of the given class.

Parameters:

  • object (Object)

    Object to test pattern against

Returns:

  • (Boolean)


376
377
378
# File 'lib/filigree/match.rb', line 376

def match?(object, _)
	object.is_a?(@pattern_elem)
end

#weightObject



380
381
382
# File 'lib/filigree/match.rb', line 380

def weight
	3
end