Class: RBI::Type::Nilable

Inherits:
Type
  • Object
show all
Defined in:
lib/rbi/type.rb

Overview

A type that can be nil like T.nilable(String).

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject (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

#normalizeObject

: -> Type



382
383
384
# File 'lib/rbi/type.rb', line 382

def normalize
  Type::Any.new([Type.simple("NilClass"), @type.normalize])
end

#simplifyObject

: -> 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_rbiObject

: -> String



376
377
378
# File 'lib/rbi/type.rb', line 376

def to_rbi
  "::T.nilable(#{@type.to_rbi})"
end