Module: CommonStruct

Included in:
ClassyStruct::ClassyStructClass, OpenStruct, Struct
Defined in:
ext/common.rb

Constant Summary collapse

DEFAULT_STRUCT_TYPE =
:classy_struct

Instance Method Summary collapse

Instance Method Details

#delete(key) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'ext/common.rb', line 16

def delete key
  key = key.to_sym
  val = send(key) rescue nil

  unless val.nil?
    send("#{key}=".to_sym, nil)
  end

  return val
end

#struct_typeObject



6
7
8
# File 'ext/common.rb', line 6

def struct_type
  DEFAULT_STRUCT_TYPE
end

#to_jsonObject



27
28
29
# File 'ext/common.rb', line 27

def to_json
  to_h.to_json
end

#to_struct(type = nil) ⇒ Object



10
11
12
13
14
# File 'ext/common.rb', line 10

def to_struct(type=nil)
  type ||= struct_type
  return self if type.to_sym == struct_type
  return self.to_h.to_struct(type)
end