Module: Ollama::DTO::ClassMethods
- Defined in:
- lib/ollama/dto.rb
Overview
Class-level helpers for DTO attribute tracking.
Instance Method Summary collapse
-
#attr_accessor(*names) ⇒ Object
The attr_accessor method extends the functionality of the standard attr_accessor by also registering the declared attributes in the class’s attributes set.
-
#attr_reader(*names) ⇒ Object
The attr_reader method extends the functionality of the standard attr_reader by also registering the declared attributes in the class’s attributes set.
-
#attributes ⇒ Set
The attributes accessor reads and writes the attributes instance variable.
- #attributes=(value) ⇒ Object
-
#from_hash(hash) ⇒ self
The from_hash method creates a new instance of the class by converting a hash into keyword arguments.
Instance Method Details
#attr_accessor(*names) ⇒ Object
The attr_accessor method extends the functionality of the standard attr_accessor by also registering the declared attributes in the class’s attributes set.
72 73 74 75 |
# File 'lib/ollama/dto.rb', line 72 def attr_accessor(*names) super attributes.merge(names.map(&:to_sym)) end |
#attr_reader(*names) ⇒ Object
The attr_reader method extends the functionality of the standard attr_reader by also registering the declared attributes in the class’s attributes set.
61 62 63 64 |
# File 'lib/ollama/dto.rb', line 61 def attr_reader(*names) super attributes.merge(names.map(&:to_sym)) end |
#attributes ⇒ Set
The attributes accessor reads and writes the attributes instance variable.
34 35 36 |
# File 'lib/ollama/dto.rb', line 34 def attributes @attributes ||= Set.new end |
#attributes=(value) ⇒ Object
38 39 40 |
# File 'lib/ollama/dto.rb', line 38 def attributes=(value) @attributes = value end |
#from_hash(hash) ⇒ self
The from_hash method creates a new instance of the class by converting a hash into keyword arguments.
This method is typically used to instantiate objects from JSON data or other hash-based sources, transforming the hash keys to symbols and passing them as keyword arguments to the constructor.
51 52 53 |
# File 'lib/ollama/dto.rb', line 51 def from_hash(hash) new(**hash.transform_keys(&:to_sym)) end |