Module: T::Props
- Included in:
- InexactStruct
- Defined in:
- lib/sorbet/eraser/t/props.rb
Overview
Here is the place we don’t match up to sorbet because we simply don’t implement as much as they do in the runtime. If there are pieces of this that folks would like implemented I’d be happy to include them. This is here just to get a baseline for folks using T::Struct with basic const/prop calls.
Defined Under Namespace
Modules: ClassMethods, Constructor, Serializable
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ Object
Here we’re going to check against the props that have been defined on the class level and set appropriate values.
Class Method Details
.included(base) ⇒ Object
10 11 12 |
# File 'lib/sorbet/eraser/t/props.rb', line 10 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#initialize(hash = {}) ⇒ Object
Here we’re going to check against the props that have been defined on the class level and set appropriate values.
41 42 43 44 45 46 47 |
# File 'lib/sorbet/eraser/t/props.rb', line 41 def initialize(hash = {}) self.class.props.each do |name, rules| instance_variable_set("@#{name}", hash.key?(name) ? hash.delete(name) : rules[:default]) end raise ArgumentError, "unknown keyword: #{hash.keys.first}" unless hash.empty? end |