Class: Terrafying::FnRef

Inherits:
Ref
  • Object
show all
Defined in:
lib/terrafying/generator.rb

Instance Method Summary collapse

Methods inherited from Ref

#<=>, #==, #[], #[]=, #downcase, #fn_call, #slice, #split, #strip, #to_s, #to_str

Constructor Details

#initialize(ref:, fn:, args: []) ⇒ FnRef

Returns a new instance of FnRef.



141
142
143
144
145
146
147
148
149
# File 'lib/terrafying/generator.rb', line 141

def initialize(
      ref:,
      fn:,
      args: []
    )
  @ref = ref
  @fn = fn
  @args = args
end

Instance Method Details

#realiseObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/terrafying/generator.rb', line 151

def realise
  ref = @ref.realise
  args = @args.map { |arg|
    if arg == ARG_PLACEHOLDER
      ref
    elsif arg.is_a? String
      "\"#{arg}\""
    else
      arg
    end
  }.join(", ")

  "#{@fn}(#{args})"
end