0

Is it possibly to dynamically set the class of an expando??

Having set

jr = new Expando()

Is there a way to

def end = 'name'

so that

jr.end

will actually give me the value stored in

jr.name

john renfrew
  • 393
  • 1
  • 9
  • 30

2 Answers2

0

I'm not sure I understand your question, maybe this will help

jr = new Expando()
jr.end = 'name'
jr.name = jr.end

assert jr.end == jr.name
assert jr.end == 'name'
Dónal
  • 185,044
  • 174
  • 569
  • 824
  • Maybe I haven't asked it in a logical way By changing the def end I want to be able to create lots of different classes i.e jr.name jr.house jr.field so that I can assign value to each of these but only if they get created. – john renfrew Aug 02 '10 at 11:34
0

fixed it, need to assign a value at the same time. Doh!

def value = 'some value'
jr."$end" = value
john renfrew
  • 393
  • 1
  • 9
  • 30