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.



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

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.



1036
1037
1038
# File 'lib/rbs/types.rb', line 1036

def required
  @required
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



1037
1038
1039
# File 'lib/rbs/types.rb', line 1037

def self_type
  @self_type
end

#typeObject (readonly)

Returns the value of attribute type.



1035
1036
1037
# File 'lib/rbs/types.rb', line 1035

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



1045
1046
1047
1048
1049
1050
# File 'lib/rbs/types.rb', line 1045

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

#map_type(&block) ⇒ Object



1068
1069
1070
1071
1072
1073
1074
# File 'lib/rbs/types.rb', line 1068

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



1060
1061
1062
1063
1064
1065
1066
# File 'lib/rbs/types.rb', line 1060

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

#to_json(state = _ = nil) ⇒ Object



1052
1053
1054
1055
1056
1057
1058
# File 'lib/rbs/types.rb', line 1052

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