Class: RBS::Types::Proc
- Inherits:
-
Object
- Object
- RBS::Types::Proc
- Defined in:
- lib/rbs/types.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #each_type(&block) ⇒ Object
- #free_variables(set = ) ⇒ Object
- #hash ⇒ Object
-
#initialize(location:, type:, block:) ⇒ Proc
constructor
A new instance of Proc.
- #map_type(&block) ⇒ Object
- #map_type_name(&block) ⇒ Object
- #sub(s) ⇒ Object
- #to_json(state = _ = nil) ⇒ Object
- #to_s(level = 0) ⇒ Object
Constructor Details
#initialize(location:, type:, block:) ⇒ Proc
Returns a new instance of Proc.
1062 1063 1064 1065 1066 |
# File 'lib/rbs/types.rb', line 1062 def initialize(location:, type:, block:) @type = type @block = block @location = location end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
1059 1060 1061 |
# File 'lib/rbs/types.rb', line 1059 def block @block end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
1060 1061 1062 |
# File 'lib/rbs/types.rb', line 1060 def location @location end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
1058 1059 1060 |
# File 'lib/rbs/types.rb', line 1058 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
1068 1069 1070 |
# File 'lib/rbs/types.rb', line 1068 def ==(other) other.is_a?(Proc) && other.type == type && other.block == block end |
#each_type(&block) ⇒ Object
1110 1111 1112 1113 1114 1115 1116 1117 |
# File 'lib/rbs/types.rb', line 1110 def each_type(&block) if block type.each_type(&block) self.block&.type&.each_type(&block) else enum_for :each_type end end |
#free_variables(set = ) ⇒ Object
1078 1079 1080 1081 1082 |
# File 'lib/rbs/types.rb', line 1078 def free_variables(set = Set[]) type.free_variables(set) block&.type&.free_variables(set) set end |
#hash ⇒ Object
1074 1075 1076 |
# File 'lib/rbs/types.rb', line 1074 def hash self.class.hash ^ type.hash ^ block.hash end |
#map_type(&block) ⇒ Object
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 |
# File 'lib/rbs/types.rb', line 1127 def map_type(&block) if block Proc.new( type: type.map_type(&block), block: self.block&.map_type(&block), location: location ) else enum_for :map_type end end |
#map_type_name(&block) ⇒ Object
1119 1120 1121 1122 1123 1124 1125 |
# File 'lib/rbs/types.rb', line 1119 def map_type_name(&block) Proc.new( type: type.map_type_name(&block), block: self.block&.map_type {|type| type.map_type_name(&block) }, location: location ) end |
#sub(s) ⇒ Object
1093 1094 1095 |
# File 'lib/rbs/types.rb', line 1093 def sub(s) self.class.new(type: type.sub(s), block: block&.sub(s), location: location) end |
#to_json(state = _ = nil) ⇒ Object
1084 1085 1086 1087 1088 1089 1090 1091 |
# File 'lib/rbs/types.rb', line 1084 def to_json(state = _ = nil) { class: :proc, type: type, block: block, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 |
# File 'lib/rbs/types.rb', line 1097 def to_s(level = 0) case when b = block if b.required "^(#{type.param_to_s}) { (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}" else "^(#{type.param_to_s}) ?{ (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}" end else "^(#{type.param_to_s}) -> #{type.return_to_s}" end end |