Class: Parlour::Types::Hash

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

Overview

A hash with known key and value types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#hash, #to_type, to_type

Constructor Details

#initialize(key, value) ⇒ Hash

Returns a new instance of Hash.



336
337
338
339
# File 'lib/parlour/types.rb', line 336

def initialize(key, value)
  @key = to_type(key)
  @value = to_type(value)
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



347
348
349
# File 'lib/parlour/types.rb', line 347

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



350
351
352
# File 'lib/parlour/types.rb', line 350

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



342
343
344
# File 'lib/parlour/types.rb', line 342

def ==(other)
  Hash === other && key == other.key && value == other.value
end

#describeObject



363
364
365
# File 'lib/parlour/types.rb', line 363

def describe
  "Hash<#{key.describe}, #{value.describe}>"
end

#generate_rbiObject



353
354
355
# File 'lib/parlour/types.rb', line 353

def generate_rbi
  "T::Hash[#{key.generate_rbi}, #{value.generate_rbi}]"
end

#generate_rbsObject



358
359
360
# File 'lib/parlour/types.rb', line 358

def generate_rbs
  "::Hash[#{key.generate_rbs}, #{value.generate_rbs}]"
end