Class: Calculi::Attribute::Abstract Abstract
- Inherits:
-
Module
- Object
- Module
- Calculi::Attribute::Abstract
- Includes:
- Utility
- Defined in:
- lib/calculi/attribute/abstract.rb
Overview
This class is abstract.
Typed attributes with defaults.
Constant Summary collapse
- NO_DEFAULT =
Object.new
- PASSTHRU =
->(o) { o }
Constants included from Utility
Utility::NON_IVAR, Utility::NULL
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#ivar_name ⇒ Object
readonly
Returns the value of attribute ivar_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#setter ⇒ Object
readonly
Returns the value of attribute setter.
Instance Method Summary collapse
- #default? ⇒ Boolean
- #default_setter ⇒ Proc abstract
-
#initialize(name, options = {}, &setter) ⇒ Abstract
constructor
A new instance of Abstract.
- #inspect ⇒ Object
- #readonly? ⇒ Boolean
Methods included from Utility
#at_prefixed, #callable?, #constantly, #eval_or_value, #instance_variable_compute, #procable?, #set_attribute
Constructor Details
#initialize(name, options = {}, &setter) ⇒ Abstract
Returns a new instance of Abstract.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/calculi/attribute/abstract.rb', line 36 def initialize(name, = {}, &setter) @name = name.to_s @ivar_name = at_prefixed name @default = .fetch :default, NO_DEFAULT @readonly = !!.fetch(:readonly, false) @setter = block_given? ? setter : .fetch(:setter) { default_setter } define_attribute_methods! end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
9 10 11 |
# File 'lib/calculi/attribute/abstract.rb', line 9 def default @default end |
#ivar_name ⇒ Object (readonly)
Returns the value of attribute ivar_name.
14 15 16 |
# File 'lib/calculi/attribute/abstract.rb', line 14 def ivar_name @ivar_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/calculi/attribute/abstract.rb', line 19 def name @name end |
#setter ⇒ Object (readonly)
Returns the value of attribute setter.
24 25 26 |
# File 'lib/calculi/attribute/abstract.rb', line 24 def setter @setter end |
Instance Method Details
#default? ⇒ Boolean
56 57 58 |
# File 'lib/calculi/attribute/abstract.rb', line 56 def default? default != NO_DEFAULT end |
#default_setter ⇒ Proc
This method is abstract.
52 53 54 |
# File 'lib/calculi/attribute/abstract.rb', line 52 def default_setter PASSTHRU end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/calculi/attribute/abstract.rb', line 60 def inspect "#{self.class}(:name, :default => #{default.inspect})" end |
#readonly? ⇒ Boolean
64 65 66 |
# File 'lib/calculi/attribute/abstract.rb', line 64 def readonly? @readonly end |