Class: Struct

Inherits:
Object
  • Object
show all
Includes:
CommonStruct
Defined in:
ext/struct.rb

Constant Summary collapse

STRUCT_TYPE =
:struct

Constants included from CommonStruct

CommonStruct::DEFAULT_STRUCT_TYPE

Instance Method Summary collapse

Methods included from CommonStruct

#delete, #to_json, #to_struct

Instance Method Details

#lockObject



40
41
42
# File 'ext/struct.rb', line 40

def lock
  self #noop
end

#merge(other) ⇒ Object

returns new object



32
33
34
35
36
37
38
# File 'ext/struct.rb', line 32

def merge other
  selfHash = self.to_h
  otherHash = other.is_a?(Hash) ? other : other.to_h

  selfHash.merge!(otherHash)
  selfHash.to_struct(STRUCT_TYPE)
end

#struct_typeObject



7
8
9
# File 'ext/struct.rb', line 7

def struct_type
  STRUCT_TYPE
end

#unlock(type = ClassyStruct::STRUCT_TYPE) ⇒ Object

Convert Struct to OpenStruct or ClassyStruct (default), thus unlocking it.



45
46
47
48
# File 'ext/struct.rb', line 45

def unlock(type=ClassyStruct::STRUCT_TYPE)
  return nil if type.to_sym == Struct::STRUCT_TYPE
  return self.to_h.to_struct(type)
end