Class: SuperStruct
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- SuperStruct
- Includes:
- Enumerable
- Defined in:
- lib/super_struct.rb
Overview
Code shamelessly stolen from errtheblog.com/post/30
Direct Known Subclasses
Instance Method Summary collapse
- #[](member) ⇒ Object
- #[]=(member, value) ⇒ Object
- #each ⇒ Object
- #each_pair ⇒ Object
- #members ⇒ Object
Instance Method Details
#[](member) ⇒ Object
24 25 26 |
# File 'lib/super_struct.rb', line 24 def [](member) send(member) end |
#[]=(member, value) ⇒ Object
28 29 30 |
# File 'lib/super_struct.rb', line 28 def []=(member, value) send("#{member}=", value) end |
#each ⇒ Object
10 11 12 13 14 15 |
# File 'lib/super_struct.rb', line 10 def each members.each do |method| yield send(method) end self end |
#each_pair ⇒ Object
17 18 19 20 21 22 |
# File 'lib/super_struct.rb', line 17 def each_pair members.each do |method| yield method, send(method) end self end |
#members ⇒ Object
6 7 8 |
# File 'lib/super_struct.rb', line 6 def members methods(false).grep(/=/).map { |m| m[0...-1] } end |