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



16
17
18
19
# File 'lib/libis/tools/extend/struct.rb', line 16

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



25
26
27
# File 'lib/libis/tools/extend/struct.rb', line 25

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



10
11
12
13
14
# File 'lib/libis/tools/extend/struct.rb', line 10

def set(h = {})
  h.symbolize_keys!
  members.each {|m| send("#{m}=", h[m]) if h.key?(m)}
  self
end

#to_jsonObject



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

def to_json
  to_hash.to_json
end