aetherknight / recursive-open-struct

OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs
Other
286 stars 54 forks source link

Cannot change the properties of a nested RecursiveOpenStruct #5

Closed SebastianVomMeer closed 11 years ago

SebastianVomMeer commented 11 years ago

I'm not sure if this is a bug or a misunderstanding of mine: I cannot change the properties of a nested RecursiveOpenStruct:

o = RecursiveOpenStruct.new a: 1, b: { c: 1 }
=> #<RecursiveOpenStruct a=1, b={:c=>1}>
irb(main):003:0> o.a
=> 1
irb(main):004:0> o.b.c
=> 1
irb(main):006:0> o.a = 2
=> 2
irb(main):005:0> o.b.c = 2
=> 2
irb(main):003:0> o.a
=> 2
irb(main):004:0> o.b.c
=> 1

Why is o.b.c still 1? Is this the expected behaviour?

recursive-open-struct (0.3.1)

aetherknight commented 11 years ago

Hi @SebastianG86,

At present, it is undefined behavior. ROS's original use-case was to make it easier to access configuration hashes, so its specs don't cover preservation of changes to sub-elements. I'll take a look into it and see if I can easily handle your use-case.

aetherknight commented 11 years ago

Fixed in commit e1729734c7290009c980e2076e0965feb694c39d and released in recursive-open-struct v0.4.2.

SebastianVomMeer commented 11 years ago

Great work, thank you so much!