Class: ValueStruct

Inherits:
Struct
  • Object
show all
Defined in:
lib/value_struct.rb,
lib/value_struct/version.rb

Defined Under Namespace

Modules: Clone, Core, DupWithChanges, Freeze, StrictArguments, ToH

Constant Summary collapse

VERSION =
'0.6.0'

Class Method Summary collapse

Class Method Details

.build(*args, &block) ⇒ Object



10
11
12
13
14
# File 'lib/value_struct.rb', line 10

def self.build(*args, &block)
  struct_class = Struct.new(*args, &block)
  struct_class.send(:include, ValueStruct::Core)
  struct_class
end

.new(*args, &block) ⇒ Object



23
24
25
26
27
# File 'lib/value_struct.rb', line 23

def self.new(*args, &block)
  mixins = [ValueStruct::DupWithChanges]
  mixins.unshift(ValueStruct::ToH) if RUBY_VERSION < "2.0"
  new_with_mixins(*args, mixins, &block)
end

.new_with_mixins(*args, mixins, &block) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
# File 'lib/value_struct.rb', line 16

def self.new_with_mixins(*args, mixins, &block)
  raise ArgumentError, 'mixin list (last paramater) must be an array' unless mixins.is_a? Array
  struct_class = build(*args, &block)
  mixins.each{ |mixin| struct_class.send(:include, mixin) }
  struct_class
end