aetherknight / recursive-open-struct

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

RecursiveOpenStruct lost when object[:prop] called instead of object.prop #16

Closed Nowaker closed 9 years ago

Nowaker commented 10 years ago

I originally thought RecursiveOpenStruck is lost after map() call. I had a mistake - I did object[:element] instead of object.element. However, shouldn't both calls just return RecursiveOpenStruck for the sake of consistency?

aetherknight commented 10 years ago

#[] is inherited from OpenStruct, and it hasn't been reimplemented. I think it makes sense to have both object[:element] and object.element return the same value.

If you'd like the behavior in RecursiveOpenStruct, feel free to submit a PR.

Nowaker commented 10 years ago

OK, thanks. This is very reasonable, because of being able to use map(&:something).inject(0, &:+). Otherwise map { |e| e[:something] }.inject(0, &:+) is needed. The first is better. :-) Will submit.