Skip to content
Discussion options

You must be logged in to vote

You'd have to pass the name in somehow to class Variable.

The simplest approach with the least amount of magic is to pass it in explicitly:

class Variable {
  type: String?
  default: String?
  name: String

  function format(): String = "${var.\(name)}"
}

vm_size = new Variable {
  type = "string"
  default = "1xCPU-1GB"
  name = "vm_size"
}

formatted_variable_name = vm_size.format()
// formatted_variable_name == "${var.vm_size}"

However, there's definitely ways to add some "magic" to fill this in. For example, here's an approach that uses toMap():

class Variable {
  type: String?
  default: String?
  name: String

  function formatted() = "${var.\(name)}"
}

vm_size: Variable = new {
  

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dshatokhin
Comment options

Answer selected by dshatokhin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants