Class: Parlour::Types::Generic

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

Overview

A user-defined generic class with an arbitrary number of type parameters. This class assumes at least one type_param is provided, otherwise output will have empty type param lists.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#hash, to_type, #to_type

Constructor Details

#initialize(type, type_params) ⇒ Generic

Returns a new instance of Generic.



204
205
206
207
# File 'lib/parlour/types.rb', line 204

def initialize(type, type_params)
  @type = to_type(type)
  @type_params = type_params.map { |p| to_type(p) }
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



217
218
219
# File 'lib/parlour/types.rb', line 217

def type
  @type
end

#type_paramsObject (readonly)

Returns the value of attribute type_params.



220
221
222
# File 'lib/parlour/types.rb', line 220

def type_params
  @type_params
end

Instance Method Details

#==(other) ⇒ Object



210
211
212
213
214
# File 'lib/parlour/types.rb', line 210

def ==(other)
  self.class === other &&
    type == other.type &&
    type_params == other.type_params
end

#describeObject



233
234
235
# File 'lib/parlour/types.rb', line 233

def describe
  "#{type.describe}<#{type_params.map(&:describe).join(', ')}>"
end

#generate_rbiObject



223
224
225
# File 'lib/parlour/types.rb', line 223

def generate_rbi
  "#{type.generate_rbi}[#{type_params.map(&:generate_rbi).join(', ')}]"
end

#generate_rbsObject



228
229
230
# File 'lib/parlour/types.rb', line 228

def generate_rbs
  "#{type.generate_rbs}[#{type_params.map(&:generate_rbs).join(', ')}]"
end