Class: Metamorpher::Builders::AST::VariableBuilder
- Inherits:
-
Object
- Object
- Metamorpher::Builders::AST::VariableBuilder
show all
- Defined in:
- lib/metamorpher/builders/ast/variable_builder.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/metamorpher/builders/ast/variable_builder.rb', line 19
def method_missing(method, *arguments, &block)
if shorthand?(method, *arguments, &block)
variable!(method.downcase.to_sym, *arguments, &block)
else
super.method_missing(method, *arguments, &block)
end
end
|
Instance Method Details
#shorthand?(method, *_arguments, &_block) ⇒ Boolean
15
16
17
|
# File 'lib/metamorpher/builders/ast/variable_builder.rb', line 15
def shorthand?(method, *_arguments, &_block)
!method[/\p{Lower}/] && !method.to_s.end_with?("_")
end
|
#variable!(name, &block) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/metamorpher/builders/ast/variable_builder.rb', line 7
def variable!(name, &block)
if block
Terms::Variable.new(name: name, condition: block)
else
Terms::Variable.new(name: name)
end
end
|