Class: Parlour::Types::Record
Overview
A record/shape; a hash with a fixed set of keys with given types.
Instance Attribute Summary collapse
-
#keys_to_types ⇒ Object
readonly
Returns the value of attribute keys_to_types.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #describe ⇒ Object
- #generate_rbi ⇒ Object
- #generate_rbs ⇒ Object
-
#initialize(keys_to_types) ⇒ Record
constructor
A new instance of Record.
Methods inherited from Type
Constructor Details
#initialize(keys_to_types) ⇒ Record
Returns a new instance of Record.
371 372 373 374 375 |
# File 'lib/parlour/types.rb', line 371 def initialize(keys_to_types) @keys_to_types = keys_to_types.map do |k, v| [k, to_type(v)] end.to_h end |
Instance Attribute Details
#keys_to_types ⇒ Object (readonly)
Returns the value of attribute keys_to_types.
383 384 385 |
# File 'lib/parlour/types.rb', line 383 def keys_to_types @keys_to_types end |
Instance Method Details
#==(other) ⇒ Object
378 379 380 |
# File 'lib/parlour/types.rb', line 378 def ==(other) Record === other && keys_to_types == other.keys_to_types end |
#describe ⇒ Object
396 397 398 |
# File 'lib/parlour/types.rb', line 396 def describe "{ #{keys_to_types.map { |k, v| "#{k}: #{v.describe}" }.join(', ')} }" end |
#generate_rbi ⇒ Object
386 387 388 |
# File 'lib/parlour/types.rb', line 386 def generate_rbi "{ #{keys_to_types.map { |k, v| "#{k}: #{v.generate_rbi}" }.join(', ')} }" end |
#generate_rbs ⇒ Object
391 392 393 |
# File 'lib/parlour/types.rb', line 391 def generate_rbs "{ #{keys_to_types.map { |k, v| "#{k}: #{v.generate_rbs}" }.join(', ')} }" end |