Class: RBS::Types::Function
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | lib/rbs/types.rb |
Class Method Summary
Instance Attribute Summary
- #empty? ⇒ Boolean readonly
- #has_classish_type? ⇒ Boolean readonly
- #has_keyword? ⇒ Boolean readonly
- #has_self_type? ⇒ Boolean readonly
- #optional_keywords readonly
- #optional_positionals readonly
- #required_keywords readonly
- #required_positionals readonly
- #rest_keywords readonly
- #rest_positionals readonly
- #return_type readonly
- #trailing_positionals readonly
- #with_nonreturn_void? ⇒ Boolean readonly
Instance Method Summary
- #==(other) (also: #eql?)
- #amap(array, &block)
- #drop_head
- #drop_tail
- #each_param(&block)
- #each_type
- #eql?(other)
- #free_variables(set = Set.new)
- #hash
- #hmapv(hash, &block)
- #map_type(&block)
- #map_type_name(&block)
- #param_to_s
- #return_to_s
- #sub(s)
- #to_json(state = _ = nil)
- #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, return_type: self.return_type)
- #with_return_type(type)
Constructor Details
.new(required_positionals:, optional_positionals:, rest_positionals:, trailing_positionals:, required_keywords:, optional_keywords:, rest_keywords:, return_type:) ⇒ Function
# File 'lib/rbs/types.rb', line 927
def initialize(required_positionals:, optional_positionals:, rest_positionals:, trailing_positionals:, required_keywords:, optional_keywords:, rest_keywords:, return_type:) @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 end
Class Method Details
.empty(return_type)
[ GitHub ]# File 'lib/rbs/types.rb', line 1077
def self.empty(return_type) Function.new( required_positionals: [], optional_positionals: [], rest_positionals: nil, trailing_positionals: [], required_keywords: {}, optional_keywords: {}, rest_keywords: nil, return_type: return_type ) end
Instance Attribute Details
#empty? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rbs/types.rb', line 1117
def empty? required_positionals.empty? && optional_positionals.empty? && !rest_positionals && trailing_positionals.empty? && required_keywords.empty? && optional_keywords.empty? && !rest_keywords end
#has_classish_type? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rbs/types.rb', line 1188
def has_classish_type? each_type.any? {|type| type.has_classish_type? } end
#has_keyword? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rbs/types.rb', line 1176
def has_keyword? if !required_keywords.empty? || !optional_keywords.empty? || rest_keywords true else false end end
#has_self_type? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rbs/types.rb', line 1184
def has_self_type? each_type.any? {|type| type.has_self_type? } end
#optional_keywords (readonly)
[ GitHub ]# File 'lib/rbs/types.rb', line 923
attr_reader :optional_keywords
#optional_positionals (readonly)
[ GitHub ]# File 'lib/rbs/types.rb', line 919
attr_reader :optional_positionals
#required_keywords (readonly)
[ GitHub ]# File 'lib/rbs/types.rb', line 922
attr_reader :required_keywords
#required_positionals (readonly)
[ GitHub ]# File 'lib/rbs/types.rb', line 918
attr_reader :required_positionals
#rest_keywords (readonly)
[ GitHub ]# File 'lib/rbs/types.rb', line 924
attr_reader :rest_keywords
#rest_positionals (readonly)
[ GitHub ]# File 'lib/rbs/types.rb', line 920
attr_reader :rest_positionals
#return_type (readonly)
[ GitHub ]# File 'lib/rbs/types.rb', line 925
attr_reader :return_type
#trailing_positionals (readonly)
[ GitHub ]# File 'lib/rbs/types.rb', line 921
attr_reader :trailing_positionals
#with_nonreturn_void? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rbs/types.rb', line 1192
def with_nonreturn_void? if each_param.any? {|param| param.type.with_nonreturn_void? } true else if return_type.is_a?(Bases::Void) false else return_type.with_nonreturn_void? end end end
Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]# File 'lib/rbs/types.rb', line 938
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.return_type == return_type end
#amap(array, &block)
[ GitHub ]# File 'lib/rbs/types.rb', line 1009
def amap(array, &block) if array.empty? _ = array else array.map(&block) end end
#drop_head
[ GitHub ]# File 'lib/rbs/types.rb', line 1146
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
[ GitHub ]# File 'lib/rbs/types.rb', line 1163
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(&block)
[ GitHub ]# File 'lib/rbs/types.rb', line 1046
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
[ GitHub ]# File 'lib/rbs/types.rb', line 1031
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
#eql?(other)
[ GitHub ]# File 'lib/rbs/types.rb', line 950
alias eql? ==
#free_variables(set = Set.new)
[ GitHub ]# File 'lib/rbs/types.rb', line 964
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
#hash
[ GitHub ]# File 'lib/rbs/types.rb', line 952
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 ^ return_type.hash end
#hmapv(hash, &block)
[ GitHub ]#map_type(&block)
[ GitHub ]# File 'lib/rbs/types.rb', line 992
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) }, return_type: yield(return_type) ) else enum_for :map_type end end
#map_type_name(&block)
[ GitHub ]# File 'lib/rbs/types.rb', line 1025
def map_type_name(&block) map_type do |type| type.map_type_name(&block) end end
#param_to_s
[ GitHub ]# File 'lib/rbs/types.rb', line 1127
def param_to_s # @type var params: Array[String] params = [] params.push(*required_positionals.map(&:to_s)) 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
[ GitHub ]# File 'lib/rbs/types.rb', line 1142
def return_to_s return_type.to_s(1) end
#sub(s)
[ GitHub ]# File 'lib/rbs/types.rb', line 1073
def sub(s) map_type {|ty| ty.sub(s) } end
#to_json(state = _ = nil)
[ GitHub ]# File 'lib/rbs/types.rb', line 1060
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, 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, return_type: self.return_type)
[ GitHub ]# File 'lib/rbs/types.rb', line 1103
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, 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, return_type: return_type ) end
#with_return_type(type)
[ GitHub ]# File 'lib/rbs/types.rb', line 1090
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, return_type: type ) end