Class: ValueStruct
- Inherits:
-
Struct
- Object
- Struct
- ValueStruct
show all
- Defined in:
- lib/value_struct.rb,
lib/value_struct/version.rb
Defined Under Namespace
Modules: Core, DupWithChanges, Freeze, StrictArguments, ToH
Constant Summary
collapse
- VERSION =
'0.5.0'
Class Method Summary
collapse
Class Method Details
.build(*args, &block) ⇒ Object
9
10
11
12
13
|
# File 'lib/value_struct.rb', line 9
def self.build(*args, &block)
struct_class = Struct.new(*args, &block)
struct_class.send(:include, ValueStruct::Core)
struct_class
end
|
.new(*args, &block) ⇒ Object
22
23
24
25
26
|
# File 'lib/value_struct.rb', line 22
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
15
16
17
18
19
20
|
# File 'lib/value_struct.rb', line 15
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
|