Skip to content

Setting values in a child object from a parent object #1058

Closed Answered by HT154
jmgilman asked this question in Q&A
Discussion options

You must be logged in to vote

If I'm interpreting your goal correctly, I think you want something like this:

class A {
  name: String
  local _a = this // this "captures" this A so it can be used unambiguously in inner scopes
  b: Mapping<String, B> = new {
    default {
      name = _a.name
    }
  }
}

class B {
  name: String
}

So writing this:

test = new A {
  name = "test"
  b {
    ["abc"] {}
    ["def"] { name = "def" }
  }
}

Produces

test {
  name = "test"
  b {
    ["abc"] {
      name = "test"
    }
    ["def"] {
      name = "def"
    }
  }
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by jmgilman
Comment options

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

HT154 May 4, 2025
Collaborator

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