Sha256: 37ab860e5e020fd49fc8681c39b14ae9fadd04e28ccb27c9851118b598cc41c4
Contents?: true
Size: 906 Bytes
Versions: 2
Compression:
Stored size: 906 Bytes
Contents
--- title: Inheritance layout: gem-single name: dry-initializer --- Subclassing preserves all definitions being made inside a superclass. ```ruby require 'dry-initializer' class User extend Dry::Initializer param :name end class Employee < User param :position end employee = Employee.new('John', 'supercargo') employee.name # => 'John' employee.position # => 'supercargo' employee = Employee.new # => fails because type ``` You can override params and options. Such overriding leaves initial order of params (positional arguments) unchanged: ```ruby class Employee < User param :position, optional: true param :name, default: proc { 'Unknown' } end user = User.new # => Boom! because User#name is required employee = Employee.new # passes because who cares on employee's name employee.name # => 'Unknown' because it is the name that positioned first like in User ```
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-initializer-3.0.3 | docsite/source/inheritance.html.md |
dry-initializer-3.0.2 | docsite/source/inheritance.html.md |