Class: Chelsy::Syntax::Coercer
- Inherits:
-
Constraint
- Object
- Constraint
- Chelsy::Syntax::Coercer
- Defined in:
- lib/chelsy/syntax.rb
Overview
This constraint accepts an instance of specific type of node, or can coerce some other type of objects to such a node.
Instance Attribute Summary
Attributes inherited from Constraint
Instance Method Summary collapse
- #accept?(node) ⇒ Boolean
- #coerce(node) ⇒ Object
-
#initialize(klass) {|value| ... } ⇒ Coercer
constructor
Initialize an instance.
Methods inherited from Constraint
Constructor Details
#initialize(klass) {|value| ... } ⇒ Coercer
Initialize an instance.
54 55 56 57 58 59 |
# File 'lib/chelsy/syntax.rb', line 54 def initialize(klass, &block) @class = klass @coercer_block = block super klass.name end |
Instance Method Details
#accept?(node) ⇒ Boolean
61 62 63 |
# File 'lib/chelsy/syntax.rb', line 61 def accept?(node) @class === node || super(node) end |
#coerce(node) ⇒ Object
65 66 67 |
# File 'lib/chelsy/syntax.rb', line 65 def coerce(node) @coercer_block.call(node) end |