Class: RBS::Types::Function
- Inherits:
-
Object
- Object
- RBS::Types::Function
- Includes:
- _ToJson
- Defined in:
- lib/rbs/types.rb,
sig/types.rbs
Defined Under Namespace
Classes: ForwardingParam, Param
Instance Attribute Summary collapse
-
#forwarding ⇒ ForwardingParam?
readonly
Returns the value of attribute forwarding.
-
#optional_keywords ⇒ Hash[Symbol, Param]
readonly
Returns the value of attribute optional_keywords.
-
#optional_positionals ⇒ Array[Param]
readonly
Returns the value of attribute optional_positionals.
-
#required_keywords ⇒ Hash[Symbol, Param]
readonly
Returns the value of attribute required_keywords.
-
#required_positionals ⇒ Array[Param]
readonly
Returns the value of attribute required_positionals.
-
#rest_keywords ⇒ Param?
readonly
Returns the value of attribute rest_keywords.
-
#rest_positionals ⇒ Param?
readonly
Returns the value of attribute rest_positionals.
-
#return_type ⇒ t
readonly
Returns the value of attribute return_type.
-
#trailing_positionals ⇒ Array[Param]
readonly
Returns the value of attribute trailing_positionals.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #amap(array, &block) ⇒ void
- #drop_head ⇒ [Param, Function]
- #drop_tail ⇒ [Param, Function]
- #each_param {|arg0| ... } ⇒ Object
- #each_type {|arg0| ... } ⇒ Object
- #empty? ⇒ Boolean
- #forwarding? ⇒ Boolean
- #free_variables(set = Set.new) ⇒ Set[Symbol]
- #has_classish_type? ⇒ Boolean
- #has_keyword? ⇒ Boolean
- #has_self_type? ⇒ Boolean
- #hash ⇒ Integer
- #hmapv(hash, &block) ⇒ void
-
#initialize(required_positionals:, optional_positionals:, rest_positionals:, trailing_positionals:, required_keywords:, optional_keywords:, rest_keywords:, return_type:, forwarding: nil) ⇒ Function
constructor
A new instance of Function.
- #map_type {|arg0| ... } ⇒ Object
- #map_type_name {|arg0, arg1, arg2| ... } ⇒ Function
- #param_to_s ⇒ String
- #return_to_s ⇒ String
- #sub(s) ⇒ Function
- #to_json(state = nil) ⇒ Object
- #update(required_positionals: self.required_positionals, optional_positionals: self.optional_positionals, rest_positionals: self.rest_positionals, trailing_positionals: self.trailing_positionals, required_keywords: self.required_keywords, optional_keywords: self.optional_keywords, rest_keywords: self.rest_keywords, forwarding: self.forwarding, return_type: self.return_type) ⇒ Object
- #with_nonreturn_void? ⇒ Boolean
- #with_return_type(type) ⇒ Function
Constructor Details
#initialize(required_positionals:, optional_positionals:, rest_positionals:, trailing_positionals:, required_keywords:, optional_keywords:, rest_keywords:, return_type:, forwarding: nil) ⇒ Function
Returns a new instance of Function.
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/rbs/types.rb', line 999 def initialize(required_positionals:, optional_positionals:, rest_positionals:, trailing_positionals:, required_keywords:, optional_keywords:, rest_keywords:, return_type:, forwarding: nil) @return_type = return_type @required_positionals = required_positionals @optional_positionals = optional_positionals @rest_positionals = rest_positionals @trailing_positionals = trailing_positionals @required_keywords = required_keywords @optional_keywords = optional_keywords @rest_keywords = rest_keywords @forwarding = forwarding end |
Instance Attribute Details
#forwarding ⇒ ForwardingParam? (readonly)
Returns the value of attribute forwarding.
996 997 998 |
# File 'lib/rbs/types.rb', line 996 def forwarding @forwarding end |
#optional_keywords ⇒ Hash[Symbol, Param] (readonly)
Returns the value of attribute optional_keywords.
994 995 996 |
# File 'lib/rbs/types.rb', line 994 def optional_keywords @optional_keywords end |
#optional_positionals ⇒ Array[Param] (readonly)
Returns the value of attribute optional_positionals.
990 991 992 |
# File 'lib/rbs/types.rb', line 990 def optional_positionals @optional_positionals end |
#required_keywords ⇒ Hash[Symbol, Param] (readonly)
Returns the value of attribute required_keywords.
993 994 995 |
# File 'lib/rbs/types.rb', line 993 def required_keywords @required_keywords end |
#required_positionals ⇒ Array[Param] (readonly)
Returns the value of attribute required_positionals.
989 990 991 |
# File 'lib/rbs/types.rb', line 989 def required_positionals @required_positionals end |
#rest_keywords ⇒ Param? (readonly)
Returns the value of attribute rest_keywords.
995 996 997 |
# File 'lib/rbs/types.rb', line 995 def rest_keywords @rest_keywords end |
#rest_positionals ⇒ Param? (readonly)
Returns the value of attribute rest_positionals.
991 992 993 |
# File 'lib/rbs/types.rb', line 991 def rest_positionals @rest_positionals end |
#return_type ⇒ t (readonly)
Returns the value of attribute return_type.
997 998 999 |
# File 'lib/rbs/types.rb', line 997 def return_type @return_type end |
#trailing_positionals ⇒ Array[Param] (readonly)
Returns the value of attribute trailing_positionals.
992 993 994 |
# File 'lib/rbs/types.rb', line 992 def trailing_positionals @trailing_positionals end |
Class Method Details
.empty(return_type) ⇒ instance
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 |
# File 'lib/rbs/types.rb', line 1156 def self.empty(return_type) Function.new( required_positionals: [], optional_positionals: [], rest_positionals: nil, trailing_positionals: [], required_keywords: {}, optional_keywords: {}, rest_keywords: nil, forwarding: nil, return_type: return_type ) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'lib/rbs/types.rb', line 1011 def ==(other) other.is_a?(Function) && other.required_positionals == required_positionals && other.optional_positionals == optional_positionals && other.rest_positionals == rest_positionals && other.trailing_positionals == trailing_positionals && other.required_keywords == required_keywords && other.optional_keywords == optional_keywords && other.rest_keywords == rest_keywords && other.forwarding == forwarding && other.return_type == return_type end |
#amap(array, &block) ⇒ void
This method returns an undefined value.
1085 1086 1087 1088 1089 1090 1091 |
# File 'lib/rbs/types.rb', line 1085 def amap(array, &block) if array.empty? _ = array else array.map(&block) end end |
#drop_head ⇒ [Param, Function]
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/rbs/types.rb', line 1234 def drop_head case when !required_positionals.empty? [ required_positionals[0], update(required_positionals: required_positionals.drop(1)) ] when !optional_positionals.empty? [ optional_positionals[0], update(optional_positionals: optional_positionals.drop(1)) ] else raise "Cannot #drop_head" end end |
#drop_tail ⇒ [Param, Function]
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 |
# File 'lib/rbs/types.rb', line 1251 def drop_tail case when !trailing_positionals.empty? last = trailing_positionals.last or raise [ last, update(trailing_positionals: trailing_positionals.take(trailing_positionals.size - 1)) ] else raise "Cannot #drop_tail" end end |
#each_param ⇒ void #each_param ⇒ Enumerator[Param, void]
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 |
# File 'lib/rbs/types.rb', line 1122 def each_param(&block) if block required_positionals.each(&block) optional_positionals.each(&block) rest_positionals&.yield_self(&block) trailing_positionals.each(&block) required_keywords.each_value(&block) optional_keywords.each_value(&block) rest_keywords&.yield_self(&block) else enum_for :each_param end end |
#each_type ⇒ void #each_type ⇒ Enumerator[t, void]
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 |
# File 'lib/rbs/types.rb', line 1107 def each_type if block_given? required_positionals.each {|param| yield param.type } optional_positionals.each {|param| yield param.type } rest_positionals&.yield_self {|param| yield param.type } trailing_positionals.each {|param| yield param.type } required_keywords.each_value {|param| yield param.type } optional_keywords.each_value {|param| yield param.type } rest_keywords&.yield_self {|param| yield param.type } yield(return_type) else enum_for :each_type end end |
#empty? ⇒ Boolean
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 |
# File 'lib/rbs/types.rb', line 1199 def empty? required_positionals.empty? && optional_positionals.empty? && !rest_positionals && trailing_positionals.empty? && required_keywords.empty? && optional_keywords.empty? && !forwarding? && !rest_keywords end |
#forwarding? ⇒ Boolean
1226 1227 1228 |
# File 'lib/rbs/types.rb', line 1226 def forwarding? !forwarding.nil? end |
#free_variables(set = Set.new) ⇒ Set[Symbol]
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
# File 'lib/rbs/types.rb', line 1039 def free_variables(set = Set.new) set.tap do required_positionals.each do |param| param.type.free_variables(set) end optional_positionals.each do |param| param.type.free_variables(set) end rest_positionals&.yield_self do |param| param.type.free_variables(set) end trailing_positionals.each do |param| param.type.free_variables(set) end required_keywords.each_value do |param| param.type.free_variables(set) end optional_keywords.each_value do |param| param.type.free_variables(set) end rest_keywords&.yield_self do |param| param.type.free_variables(set) end return_type.free_variables(set) end end |
#has_classish_type? ⇒ Boolean
1276 1277 1278 |
# File 'lib/rbs/types.rb', line 1276 def has_classish_type? each_type.any? {|type| type.has_classish_type? } end |
#has_keyword? ⇒ Boolean
1264 1265 1266 1267 1268 1269 1270 |
# File 'lib/rbs/types.rb', line 1264 def has_keyword? if !required_keywords.empty? || !optional_keywords.empty? || rest_keywords true else false end end |
#has_self_type? ⇒ Boolean
1272 1273 1274 |
# File 'lib/rbs/types.rb', line 1272 def has_self_type? each_type.any? {|type| type.has_self_type? } end |
#hash ⇒ Integer
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 |
# File 'lib/rbs/types.rb', line 1026 def hash self.class.hash ^ required_positionals.hash ^ optional_positionals.hash ^ rest_positionals.hash ^ trailing_positionals.hash ^ required_keywords.hash ^ optional_keywords.hash ^ rest_keywords.hash ^ forwarding.hash ^ return_type.hash end |
#hmapv(hash, &block) ⇒ void
This method returns an undefined value.
1093 1094 1095 1096 1097 1098 1099 |
# File 'lib/rbs/types.rb', line 1093 def hmapv(hash, &block) if hash.empty? _ = hash else hash.transform_values(&block) end end |
#map_type ⇒ Function #map_type ⇒ Enumerator[t, Function]
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'lib/rbs/types.rb', line 1067 def map_type(&block) if block Function.new( required_positionals: amap(required_positionals) {|param| param.map_type(&block) }, optional_positionals: amap(optional_positionals) {|param| param.map_type(&block) }, rest_positionals: rest_positionals&.yield_self {|param| param.map_type(&block) }, trailing_positionals: amap(trailing_positionals) {|param| param.map_type(&block) }, required_keywords: hmapv(required_keywords) {|param| param.map_type(&block) }, optional_keywords: hmapv(optional_keywords) {|param| param.map_type(&block) }, rest_keywords: rest_keywords&.yield_self {|param| param.map_type(&block) }, forwarding: forwarding, return_type: yield(return_type) ) else enum_for :map_type end end |
#map_type_name {|arg0, arg1, arg2| ... } ⇒ Function
1101 1102 1103 1104 1105 |
# File 'lib/rbs/types.rb', line 1101 def map_type_name(&block) map_type do |type| type.map_type_name(&block) end end |
#param_to_s ⇒ String
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 |
# File 'lib/rbs/types.rb', line 1210 def param_to_s # @type var params: Array[String] params = [] params.push(*required_positionals.map(&:to_s)) params.push(forwarding.to_s) if forwarding params.push(*optional_positionals.map {|p| "?#{p}"}) params.push("*#{rest_positionals}") if rest_positionals params.push(*trailing_positionals.map(&:to_s)) params.push(*required_keywords.map {|name, param| "#{name}: #{param}" }) params.push(*optional_keywords.map {|name, param| "?#{name}: #{param}" }) params.push("**#{rest_keywords}") if rest_keywords params.join(", ") end |
#return_to_s ⇒ String
1230 1231 1232 |
# File 'lib/rbs/types.rb', line 1230 def return_to_s return_type.to_s(1) end |
#sub(s) ⇒ Function
1150 1151 1152 1153 1154 |
# File 'lib/rbs/types.rb', line 1150 def sub(s) return self if s.empty? map_type {|ty| ty.sub(s) } end |
#to_json(state = nil) ⇒ Object
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 |
# File 'lib/rbs/types.rb', line 1136 def to_json(state = nil) { required_positionals: required_positionals, optional_positionals: optional_positionals, rest_positionals: rest_positionals, trailing_positionals: trailing_positionals, required_keywords: required_keywords, optional_keywords: optional_keywords, rest_keywords: rest_keywords, forwarding: forwarding, return_type: return_type }.to_json(state) end |
#update(required_positionals: self.required_positionals, optional_positionals: self.optional_positionals, rest_positionals: self.rest_positionals, trailing_positionals: self.trailing_positionals, required_keywords: self.required_keywords, optional_keywords: self.optional_keywords, rest_keywords: self.rest_keywords, forwarding: self.forwarding, return_type: self.return_type) ⇒ Object
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
# File 'lib/rbs/types.rb', line 1184 def update(required_positionals: self.required_positionals, optional_positionals: self.optional_positionals, rest_positionals: self.rest_positionals, trailing_positionals: self.trailing_positionals, required_keywords: self.required_keywords, optional_keywords: self.optional_keywords, rest_keywords: self.rest_keywords, forwarding: self.forwarding, return_type: self.return_type) Function.new( required_positionals: required_positionals, optional_positionals: optional_positionals, rest_positionals: rest_positionals, trailing_positionals: trailing_positionals, required_keywords: required_keywords, optional_keywords: optional_keywords, rest_keywords: rest_keywords, forwarding: forwarding, return_type: return_type ) end |
#with_nonreturn_void? ⇒ Boolean
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 |
# File 'lib/rbs/types.rb', line 1280 def with_nonreturn_void? if each_param.any? {|param| param.type.with_nonreturn_void? } # steep:ignore DeprecatedReference true else if return_type.is_a?(Bases::Void) false else return_type.with_nonreturn_void? # steep:ignore DeprecatedReference end end end |
#with_return_type(type) ⇒ Function
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 |
# File 'lib/rbs/types.rb', line 1170 def with_return_type(type) Function.new( required_positionals: required_positionals, optional_positionals: optional_positionals, rest_positionals: rest_positionals, trailing_positionals: trailing_positionals, required_keywords: required_keywords, optional_keywords: optional_keywords, rest_keywords: rest_keywords, forwarding: forwarding, return_type: type ) end |