In tonight's meeting I tried, and failed, to show how to create a
Struct with a custom method.
Turns out, you can't do that. But you can use UPDATE: You can do this. I don't remember what syntax I was trying before, but in 1.9.3 you can successfully pass a block to
Class.new to accomplish this.
Struct.new; though this isn't documented.
The end result is the same:
- A new
- Default initialize handling the attributes
attr_accessormethods defined for those attributes
Big thanks to @steveklabnik for his two posts which inspired me to try to show this horribleness (that's a reflection on my silliness, not Steve):