Class: Parlour::Types::Nilable

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

Overview

A type which can be either the wrapped type, or nil.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#hash, #to_type, to_type

Constructor Details

#initialize(type) ⇒ Nilable

Returns a new instance of Nilable.



78
79
80
# File 'lib/parlour/types.rb', line 78

def initialize(type)
  @type = to_type(type)
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



88
89
90
# File 'lib/parlour/types.rb', line 88

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



83
84
85
# File 'lib/parlour/types.rb', line 83

def ==(other)
  Nilable === other && type == other.type
end

#describeObject



101
102
103
# File 'lib/parlour/types.rb', line 101

def describe
  "Nilable<#{type.describe}>"
end

#generate_rbiObject



91
92
93
# File 'lib/parlour/types.rb', line 91

def generate_rbi
  "T.nilable(#{type.generate_rbi})"
end

#generate_rbsObject



96
97
98
# File 'lib/parlour/types.rb', line 96

def generate_rbs
  "#{type.generate_rbs}?"
end