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
: Type.
Instance Method Summary collapse
-
#==(other) ⇒ Object
: (BasicObject other) -> bool.
-
#initialize(type) ⇒ Nilable
constructor
: (Type type) -> void.
-
#normalize ⇒ Object
: -> Type.
-
#simplify ⇒ Object
: -> Type.
-
#to_rbi ⇒ Object
: -> String.
Constructor Details
#initialize(type) ⇒ Nilable
: (Type type) -> void
363 364 365 366 |
# File 'lib/rbi/type.rb', line 363 def initialize(type) super() @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
: Type
360 361 362 |
# File 'lib/rbi/type.rb', line 360 def type @type end |
Instance Method Details
#==(other) ⇒ Object
: (BasicObject other) -> bool
370 371 372 |
# File 'lib/rbi/type.rb', line 370 def ==(other) Nilable === other && @type == other.type end |
#normalize ⇒ Object
: -> Type
382 383 384 |
# File 'lib/rbi/type.rb', line 382 def normalize Type::Any.new([Type.simple("NilClass"), @type.normalize]) end |
#simplify ⇒ Object
: -> Type
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
: -> String
376 377 378 |
# File 'lib/rbi/type.rb', line 376 def to_rbi "::T.nilable(#{@type.to_rbi})" end |