Class: Ducktrap::Nary::Builder

Inherits:
Builder
  • Object
show all
Defined in:
lib/ducktrap/nary.rb

Overview

Builder for nary ducktraps

Instance Attribute Summary collapse

Attributes inherited from Builder

#klass

Instance Method Summary collapse

Constructor Details

#initialize(klass, body = []) ⇒ Builder

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.

Initialize object

Parameters:

  • klass (Class)

    the klass to build

  • body (Enumerable<Ducktrap>) (defaults to: [])

    the body of nary ducktrap



61
62
63
64
# File 'lib/ducktrap/nary.rb', line 61

def initialize(klass, body = [])
  @body = body
  super(klass)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object

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.

Hook called when method is missing

Returns:

  • (Object)


27
28
29
30
# File 'lib/ducktrap/nary.rb', line 27

def method_missing(name, *arguments, &block)
  builder = DSL.lookup(name) { super }
  add(builder.build(*arguments, &block))
end

Instance Attribute Details

#bodyEnumerable<Ducktrap> (readonly)

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.

Return body

Returns:



49
50
51
# File 'lib/ducktrap/nary.rb', line 49

def body
  @body
end

Instance Method Details

#add(ducktrap) ⇒ self

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.

Add ducktrap argument

Parameters:

Returns:

  • (self)


16
17
18
19
# File 'lib/ducktrap/nary.rb', line 16

def add(ducktrap)
  body << ducktrap
  self
end

#objectObject

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.

Return build instance

Returns:

  • (Object)


38
39
40
# File 'lib/ducktrap/nary.rb', line 38

def object
  @klass.new(body)
end