Class: Parlour::Types::Record

Inherits:
Type
  • Object
show all
Defined in:
lib/parlour/types.rb

Overview

A record/shape; a hash with a fixed set of keys with given types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#hash, #to_type, to_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_typesObject (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

#describeObject



396
397
398
# File 'lib/parlour/types.rb', line 396

def describe
  "{ #{keys_to_types.map { |k, v| "#{k}: #{v.describe}" }.join(', ')} }"
end

#generate_rbiObject



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_rbsObject



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