class Striuct::ClassMethods::Attributes
Attributes
for autonym of each member
Constants
- BOOLEANS
- VALUES
Public Class Methods
new()
click to toggle source
# File lib/striuct/classmethods/attributes.rb, line 16 def initialize @hash = { must: false, safety_setter: false, safety_getter: false } end
Public Instance Methods
adjuster=(adjuster)
click to toggle source
# File lib/striuct/classmethods/attributes.rb, line 42 def adjuster=(adjuster) unless Striuct.adjustable?(adjuster) raise ArgumentError, 'wrong object for adjuster' end @hash[:adjuster] = adjuster end
check_default_lazy_proc(proc)
click to toggle source
# File lib/striuct/classmethods/attributes.rb, line 84 def check_default_lazy_proc(proc) raise TypeError unless proc.respond_to?(:call) arity = proc.arity unless arity <= 2 raise ArgumentError, "wrong number of block parameter #{arity} for 0..2" end end
condition=(condition)
click to toggle source
# File lib/striuct/classmethods/attributes.rb, line 34 def condition=(condition) unless Eqq.valid?(condition) raise TypeError, 'wrong object for condition' end @hash[:condition] = condition end
default_type()
click to toggle source
# File lib/striuct/classmethods/attributes.rb, line 70 def default_type @hash.fetch(:default_type) end
default_value()
click to toggle source
# File lib/striuct/classmethods/attributes.rb, line 66 def default_value @hash.fetch(:default_value) end
dup()
click to toggle source
Calls superclass method
# File lib/striuct/classmethods/attributes.rb, line 99 def dup ret = super @hash = @hash.dup ret end
freeze()
click to toggle source
Calls superclass method
# File lib/striuct/classmethods/attributes.rb, line 93 def freeze ret = super @hash.freeze ret end
set_default(value, type)
click to toggle source
@param [Symbol] type - :value / :lazy
# File lib/striuct/classmethods/attributes.rb, line 75 def set_default(value, type) raise TypeError unless type.equal?(:value) || type.equal?(:lazy) check_default_lazy_proc(value) if type.equal?(:lazy) @hash[:default_type] = type @hash[:default_value] = value end
with_default?()
click to toggle source
# File lib/striuct/classmethods/attributes.rb, line 62 def with_default? @hash.key?(:default_value) end
Private Instance Methods
initialize_copy(original)
click to toggle source
Calls superclass method
# File lib/striuct/classmethods/attributes.rb, line 107 def initialize_copy(original) ret = super(original) @hash = @hash.dup ret end