Module: Eqq
- Extended by:
- Buildable
- Defined in:
- lib/eqq.rb,
lib/eqq.rb,
lib/eqq/version.rb,
lib/eqq/buildable.rb
Overview
Pattern objects builder
Defined Under Namespace
Modules: Buildable Classes: Error, InvalidProductError
Constant Summary collapse
- VERSION =
This will be same as latest published gem version
'0.1.1'
Constants included from Buildable
Buildable::INSPECTION_FALLBACK
Class Method Summary collapse
-
.build(&block) ⇒ Proc
In the block scope, all builder methods can be used without receiver.
- .pattern?(object) ⇒ Boolean
- .satisfy?(object) ⇒ Boolean private
Methods included from Buildable
AND, ANYTHING, BOOLEAN, CAN, EQ, NAND, NEVER, NIL, NOR, NOT, OR, QUIET, RESCUE, SAME, SEND, XOR, define_inspect_on, safe_inspect_for, validate_patterns
Class Method Details
.build(&block) ⇒ Proc
In the block scope, all builder methods can be used without receiver
40 41 42 43 44 45 46 47 |
# File 'lib/eqq.rb', line 40 def build(&block) raise ArgumentError, 'might be misused the `Eqq.build` in your code' unless block pattern = DSLScope.new.instance_exec(&block) raise InvalidProductError, 'might be misused the `Eqq.build` in your code' unless satisfy?(pattern) pattern end |
.pattern?(object) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/eqq.rb', line 18 def pattern?(object) case object when Proc, Method object.arity == 1 else begin object.respond_to?(:===) rescue NoMethodError false end end end |
.satisfy?(object) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/eqq.rb', line 32 def satisfy?(object) (Proc === object) && object.lambda? && (object.arity == 1) && object.respond_to?(:inspect) end |