Class: Virtus::Attribute::Boolean
- Inherits:
-
Object
- Object
- Virtus::Attribute
- Object
- Virtus::Attribute::Boolean
- Defined in:
- lib/virtus/attribute/boolean.rb
Overview
Bolean attribute allows true or false values to be set Additionally it adds boolean reader method, like “admin?”
Constant Summary
Constants inherited from Virtus::Attribute
Constants included from TypeLookup
Instance Attribute Summary
Attributes inherited from Virtus::Attribute
#coercion_method, #default, #instance_variable_name, #name, #options, #reader_visibility, #writer_visibility
Class Method Summary collapse
-
.primitive?(value) ⇒ Boolean
Returns if the given value is either true or false.
Instance Method Summary collapse
-
#define_reader_method(mod) ⇒ self
private
Creates standard and boolean attribute reader methods.
Methods inherited from Virtus::Attribute
#coerce, #define_writer_method, #get, #get!, #initialize, #inspect, #set, #set!
Methods included from DescendantsTracker
Methods included from TypeLookup
Methods included from Options
#accept_options, #accepted_options, #options
Constructor Details
This class inherits a constructor from Virtus::Attribute
Class Method Details
.primitive?(value) ⇒ Boolean
Returns if the given value is either true or false
32 33 34 |
# File 'lib/virtus/attribute/boolean.rb', line 32 def self.primitive?(value) value.equal?(true) || value.equal?(false) end |
Instance Method Details
#define_reader_method(mod) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates standard and boolean attribute reader methods
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/virtus/attribute/boolean.rb', line 43 def define_reader_method(mod) super reader_method_name = "#{name}?" attribute = self mod.send(:define_method, reader_method_name) { attribute.get(self) } mod.send(reader_visibility, reader_method_name) self end |