Class: Steep::Interface::MethodType
- Inherits:
-
Object
- Object
- Steep::Interface::MethodType
- Defined in:
- lib/steep/interface/method_type.rb
Constant Summary collapse
- NONE =
Object.new
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#return_type ⇒ Object
readonly
Returns the value of attribute return_type.
-
#type_params ⇒ Object
readonly
Returns the value of attribute type_params.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each_type(&block) ⇒ Object
- #free_variables ⇒ Object
-
#initialize(type_params:, params:, block:, return_type:, location:) ⇒ MethodType
constructor
A new instance of MethodType.
- #instantiate(s) ⇒ Object
- #subst(s) ⇒ Object
- #to_s ⇒ Object
- #with(type_params: NONE, params: NONE, block: NONE, return_type: NONE, location: NONE) ⇒ Object
Constructor Details
#initialize(type_params:, params:, block:, return_type:, location:) ⇒ MethodType
Returns a new instance of MethodType.
223 224 225 226 227 228 229 |
# File 'lib/steep/interface/method_type.rb', line 223 def initialize(type_params:, params:, block:, return_type:, location:) @type_params = type_params @params = params @block = block @return_type = return_type @location = location end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
217 218 219 |
# File 'lib/steep/interface/method_type.rb', line 217 def block @block end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
219 220 221 |
# File 'lib/steep/interface/method_type.rb', line 219 def location @location end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
216 217 218 |
# File 'lib/steep/interface/method_type.rb', line 216 def params @params end |
#return_type ⇒ Object (readonly)
Returns the value of attribute return_type.
218 219 220 |
# File 'lib/steep/interface/method_type.rb', line 218 def return_type @return_type end |
#type_params ⇒ Object (readonly)
Returns the value of attribute type_params.
215 216 217 |
# File 'lib/steep/interface/method_type.rb', line 215 def type_params @type_params end |
Instance Method Details
#==(other) ⇒ Object
231 232 233 234 235 236 237 238 |
# File 'lib/steep/interface/method_type.rb', line 231 def ==(other) other.is_a?(self.class) && other.type_params == type_params && other.params == params && other.block == block && other.return_type == return_type && (!other.location || !location || other.location == location) end |
#each_type(&block) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/steep/interface/method_type.rb', line 256 def each_type(&block) if block_given? params.each_type(&block) self.block&.tap do self.block.params.each_type(&block) yield(self.block.return_type) end yield(return_type) else enum_for :each_type end end |
#free_variables ⇒ Object
240 241 242 |
# File 'lib/steep/interface/method_type.rb', line 240 def free_variables (params.free_variables + (block&.free_variables || Set.new) + return_type.free_variables) - Set.new(type_params) end |
#instantiate(s) ⇒ Object
269 270 271 272 273 274 275 276 277 |
# File 'lib/steep/interface/method_type.rb', line 269 def instantiate(s) self.class.new( type_params: [], params: params.subst(s), block: block&.subst(s), return_type: return_type.subst(s), location: location, ) end |
#subst(s) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/steep/interface/method_type.rb', line 244 def subst(s) s_ = s.except(type_params) self.class.new( type_params: type_params, params: params.subst(s_), block: block&.subst(s_), return_type: return_type.subst(s_), location: location ) end |
#to_s ⇒ Object
289 290 291 292 293 294 295 |
# File 'lib/steep/interface/method_type.rb', line 289 def to_s type_params = !self.type_params.empty? ? "<#{self.type_params.map{|x| "'#{x}" }.join(", ")}> " : "" params = self.params.to_s block = self.block ? " #{self.block}" : "" "#{type_params}#{params}#{block} -> #{return_type}" end |
#with(type_params: NONE, params: NONE, block: NONE, return_type: NONE, location: NONE) ⇒ Object
279 280 281 282 283 284 285 286 287 |
# File 'lib/steep/interface/method_type.rb', line 279 def with(type_params: NONE, params: NONE, block: NONE, return_type: NONE, location: NONE) self.class.new( type_params: type_params.equal?(NONE) ? self.type_params : type_params, params: params.equal?(NONE) ? self.params : params, block: block.equal?(NONE) ? self.block : block, return_type: return_type.equal?(NONE) ? self.return_type : return_type, location: location.equal?(NONE) ? self.location : location ) end |