Class: RBS::Types::Block

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, required:, self_type: nil) ⇒ Block

Returns a new instance of Block.



1043
1044
1045
1046
1047
# File 'lib/rbs/types.rb', line 1043

def initialize(type:, required:, self_type: nil)
  @type = type
  @required = required ? true : false
  @self_type = self_type
end

Instance Attribute Details

#requiredObject (readonly)

Returns the value of attribute required.



1040
1041
1042
# File 'lib/rbs/types.rb', line 1040

def required
  @required
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



1041
1042
1043
# File 'lib/rbs/types.rb', line 1041

def self_type
  @self_type
end

#typeObject (readonly)

Returns the value of attribute type.



1039
1040
1041
# File 'lib/rbs/types.rb', line 1039

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



1049
1050
1051
1052
1053
1054
# File 'lib/rbs/types.rb', line 1049

def ==(other)
  other.is_a?(Block) &&
    other.type == type &&
    other.required == required &&
    other.self_type == self_type
end

#map_type(&block) ⇒ Object



1072
1073
1074
1075
1076
1077
1078
# File 'lib/rbs/types.rb', line 1072

def map_type(&block)
  Block.new(
    required: required,
    type: type.map_type(&block),
    self_type: self_type ? yield(self_type) : nil
  )
end

#sub(s) ⇒ Object



1064
1065
1066
1067
1068
1069
1070
# File 'lib/rbs/types.rb', line 1064

def sub(s)
  self.class.new(
    type: type.sub(s),
    required: required,
    self_type: self_type&.sub(s)
  )
end

#to_json(state = _ = nil) ⇒ Object



1056
1057
1058
1059
1060
1061
1062
# File 'lib/rbs/types.rb', line 1056

def to_json(state = _ = nil)
  {
    type: type,
    required: required,
    self_type: self_type
  }.to_json(state)
end