Class: Struct

Inherits:
Object show all
Defined in:
lib/libis/tools/extend/struct.rb

Direct Known Subclasses

Libis::Tools::Parameter

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

def to_hash

members.inject({}) {|h,m| h[m] = send(m); h}

end unless method_defined? :to_hash



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_jsonObject



22
23
24
# File 'lib/libis/tools/extend/struct.rb', line 22

def to_json
  to_hash.to_json
end