Class: Metamorpher::Builders::AST::LiteralBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/metamorpher/builders/ast/literal_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



15
16
17
18
19
20
21
# File 'lib/metamorpher/builders/ast/literal_builder.rb', line 15

def method_missing(method, *arguments, &block)
  if shorthand?(method, *arguments, &block)
    literal!(method, *arguments)
  else
    super.method_missing(method, *arguments, &block)
  end
end

Instance Method Details

#literal!(name, *children) ⇒ Object



7
8
9
# File 'lib/metamorpher/builders/ast/literal_builder.rb', line 7

def literal!(name, *children)
  Terms::Literal.new(name: name, children: children.map(&method(:termify)))
end

#shorthand?(method, *_arguments, &_block) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/metamorpher/builders/ast/literal_builder.rb', line 11

def shorthand?(method, *_arguments, &_block)
  !method[/\p{Upper}/]
end