Class: Sheetah::AttributeTypes::Value
- Inherits:
-
Object
- Object
- Sheetah::AttributeTypes::Value
- Defined in:
- lib/sheetah/attribute_types/value.rb
Instance Attribute Summary collapse
- #required ⇒ Boolean readonly
- #type ⇒ Symbol readonly
Class Method Summary collapse
-
.build(arg) ⇒ Value
A smarter version of #initialize.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(type:, required: true) ⇒ Value
constructor
A new instance of Value.
Constructor Details
#initialize(type:, required: true) ⇒ Value
Returns a new instance of Value.
44 45 46 47 |
# File 'lib/sheetah/attribute_types/value.rb', line 44 def initialize(type:, required: true) @type = type @required = required end |
Instance Attribute Details
#required ⇒ Boolean (readonly)
53 54 55 |
# File 'lib/sheetah/attribute_types/value.rb', line 53 def required @required end |
#type ⇒ Symbol (readonly)
50 51 52 |
# File 'lib/sheetah/attribute_types/value.rb', line 50 def type @type end |
Class Method Details
.build(type: , required: ) ⇒ Value .build(type) ⇒ Value
A smarter version of #initialize.
-
It automatically freezes the instance before returning it.
-
It accepts two kinds of parameters: either those of #initialize, or a shortcut. See the overloaded method signature for details.
25 26 27 28 |
# File 'lib/sheetah/attribute_types/value.rb', line 25 def self.build(arg) value = arg.is_a?(Hash) ? new(**arg) : from_type_name(arg) value.freeze end |
Instance Method Details
#==(other) ⇒ Object
55 56 57 58 59 |
# File 'lib/sheetah/attribute_types/value.rb', line 55 def ==(other) other.is_a?(self.class) && type == other.type && required == other.required end |