Class: RBI::Type::Nilable
- Inherits:
-
Type
- Object
- Type
- RBI::Type::Nilable
- Defined in:
- lib/rbi/type.rb
Overview
A type that can be nil like T.nilable(String).
Instance Attribute Summary collapse
- #type ⇒ Object readonly
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(type) ⇒ Nilable
constructor
A new instance of Nilable.
- #normalize ⇒ Object
- #simplify ⇒ Object
- #to_rbi ⇒ Object
Constructor Details
#initialize(type) ⇒ Nilable
Returns a new instance of Nilable.
363 364 365 366 |
# File 'lib/rbi/type.rb', line 363 def initialize(type) super() @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
360 361 362 |
# File 'lib/rbi/type.rb', line 360 def type @type end |
Instance Method Details
#==(other) ⇒ Object
370 371 372 |
# File 'lib/rbi/type.rb', line 370 def ==(other) Nilable === other && @type == other.type end |
#normalize ⇒ Object
382 383 384 |
# File 'lib/rbi/type.rb', line 382 def normalize Type::Any.new([Type.simple("NilClass"), @type.normalize]) end |
#simplify ⇒ Object
388 389 390 391 392 393 394 395 396 397 |
# File 'lib/rbi/type.rb', line 388 def simplify case @type when Nilable @type.simplify when Untyped @type.simplify else self end end |
#to_rbi ⇒ Object
376 377 378 |
# File 'lib/rbi/type.rb', line 376 def to_rbi "::T.nilable(#{@type.to_rbi})" end |