Class: Struct
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_hash(h) ⇒ Object
17 18 19 20 |
# File 'lib/libis/tools/extend/struct.rb', line 17 def self.from_hash(h) h.symbolize_keys! members.inject(new) {|o,m| o[m] = h[m] if h.key?(m); o} end |
.from_json(j) ⇒ Object
26 27 28 |
# File 'lib/libis/tools/extend/struct.rb', line 26 def self.from_json(j) from_hash(JSON.parse(j)) end |
Instance Method Details
#set(h = {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/libis/tools/extend/struct.rb', line 11 def set(h = {}) h.symbolize_keys! members.each {|m| send("#{m}=", h[m]) if h.key?(m)} self end |
#to_hash ⇒ Object
7 8 9 |
# File 'lib/libis/tools/extend/struct.rb', line 7 def to_hash members.inject({}) {|h,m| h[m] = send(m); h} end |
#to_json ⇒ Object
22 23 24 |
# File 'lib/libis/tools/extend/struct.rb', line 22 def to_json to_hash.to_json end |