Module: Filigree

Defined in:
lib/filigree/match.rb,
lib/filigree/types.rb,
lib/filigree/version.rb,
lib/filigree/visitor.rb,
lib/filigree/commands.rb,
lib/filigree/application.rb,
lib/filigree/configuration.rb,
lib/filigree/abstract_class.rb,
lib/filigree/class_methods_module.rb

Overview

Classes and Modules #

Defined Under Namespace

Modules: AbstractClass, Application, ClassMethodsModule, Commands, Configuration, Destructurable, TypedClass, Visitable, Visitor Classes: BasicPattern, BindingPattern, DestructuringPattern, InstancePattern, LiteralPattern, MatchEnvironment, MultipleObjectPattern, OuterPattern, RegexpPattern, SingleObjectPattern, TourGuide, WildcardPattern

Constant Summary collapse

VERSION =
'0.3.3'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap_pattern_elements(pattern) ⇒ Array<BasicPattern>

Wrap non-pattern objects in pattern objects so they can all be treated in the same way during pattern sorting and matching.

Parameters:

Returns:



177
178
179
180
181
182
183
184
185
186
# File 'lib/filigree/match.rb', line 177

def Filigree::wrap_pattern_elements(pattern)
	pattern.map do |el|
		case el
		when BasicPattern then el
		when Class        then InstancePattern.new(el)
		when Regexp       then RegexpPattern.new(el)
		else                   LiteralPattern.new(el)
		end
	end
end

Instance Method Details

#match(*objects, &block) ⇒ Object

Returns Result of evaluating the matched pattern’s block.

Examples:

Using guard clauses

match o do
  with(n, -> { n < 0 }) { :NEG  }
  with(0)               { :ZERO }
  with(n, -> { n > 0 }) { :POS  }
end

Parameters:

  • objects (Object)

    Objects to be matched

  • block (Proc)

    Block containing with clauses.

Returns:

  • (Object)

    Result of evaluating the matched pattern’s block



163
164
165
166
167
168
169
# File 'lib/filigree/match.rb', line 163

def match(*objects, &block)
	me = Filigree::MatchEnvironment.new

	me.instance_exec &block

	me.find_match(objects)
end