Class: MiniCamel::StrictDto
- Defined in:
- lib/mini_camel/strict_dto.rb
Overview
A StrictDTO is stricter than a common open struct object. It will throw an argument error if the key / method you ask for does not exist.
Direct Known Subclasses
Instance Method Summary collapse
- #[](key) ⇒ Object
- #fetch(key, default: nil) ⇒ Object
- #method_missing(method_name, *arguments, &block) ⇒ Object
Methods inherited from Dto
build, deep_build, empty, #initialize, #update
Constructor Details
This class inherits a constructor from MiniCamel::Dto
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/mini_camel/strict_dto.rb', line 20 def method_missing(method_name, *arguments, &block) if respond_to?(method_name) || method_name.to_s.end_with?('=') super else raise_key_not_found!(method_name) end end |
Instance Method Details
#[](key) ⇒ Object
7 8 9 |
# File 'lib/mini_camel/strict_dto.rb', line 7 def [](key) fetch(key) end |
#fetch(key, default: nil) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/mini_camel/strict_dto.rb', line 11 def fetch(key, default: nil) if @table.has_key?(key) @table.fetch(key, default) else return default unless default.nil? raise_key_not_found!(key) end end |