class ShapeOf::Pattern
Matches a Regexp against a String using Regexp#match?. Pretty much a wrapper around Regexp because a Regexp instance will be tested for equality in the ShapeOf::Hash
and ShapeOf::Array
since it's not a class.
Public Class Methods
[](shape)
click to toggle source
# File lib/shape_of.rb, line 326 def self.[](shape) raise TypeError, "Shape must be #{Regexp.inspect}, was #{shape.inspect}" unless shape.instance_of? Regexp Class.new(self) do @class_name = "#{superclass.name}[#{shape.inspect}]" @shape = shape def self.name @class_name end def self.to_s @class_name end def self.inspect @class_name end def self.shape_of?(object) raise TypeError, "expected #{String.inspect}, was instead #{object.inspect}" unless object.instance_of?(String) @shape.match?(object) end end end
inspect()
click to toggle source
# File lib/shape_of.rb, line 341 def self.inspect @class_name end
name()
click to toggle source
# File lib/shape_of.rb, line 333 def self.name @class_name end
shape_of?(object)
click to toggle source
# File lib/shape_of.rb, line 345 def self.shape_of?(object) raise TypeError, "expected #{String.inspect}, was instead #{object.inspect}" unless object.instance_of?(String) @shape.match?(object) end
to_s()
click to toggle source
# File lib/shape_of.rb, line 337 def self.to_s @class_name end