Class: ValueStruct
- Inherits:
-
Struct
- Object
- Struct
- ValueStruct
show all
- Defined in:
- lib/value_struct.rb,
lib/value_struct/version.rb
Defined Under Namespace
Modules: DupWithChanges, Freeze, Immutable, NoClone, StrictArguments
Constant Summary
collapse
- VERSION =
'0.8.0'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.build ⇒ Object
11
|
# File 'lib/value_struct.rb', line 11
alias build new
|
.new(*args, &block) ⇒ Object
29
30
31
32
|
# File 'lib/value_struct.rb', line 29
def new(*args, &block)
mixins = [ValueStruct::DupWithChanges]
new_with_mixins(*args, mixins, &block)
end
|
.new_with_mixins(*args, mixins, &block) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/value_struct.rb', line 13
def 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)
struct_class.send(:include, ValueStruct::Immutable)
mixins.each{ |mixin|
if mixin.is_a?(Symbol) mixin = ValueStruct.const_get(mixin.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase })
end
struct_class.send(:include, mixin)
}
struct_class
end
|
Instance Method Details
#inspect ⇒ Object
35
36
37
|
# File 'lib/value_struct.rb', line 35
def inspect
super.to_s.sub('struct', 'ValueStruct')
end
|