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_name(&block) ⇒ Object
- #sub(s) ⇒ Object
- #to_json(*a) ⇒ Object
- #to_s(level = 0) ⇒ Object
Constructor Details
#initialize(location:, type:, block:) ⇒ Proc
Returns a new instance of Proc.
996 997 998 999 1000 |
# File 'lib/rbs/types.rb', line 996 def initialize(location:, type:, block:) @type = type @block = block @location = location end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
993 994 995 |
# File 'lib/rbs/types.rb', line 993 def block @block end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
994 995 996 |
# File 'lib/rbs/types.rb', line 994 def location @location end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
992 993 994 |
# File 'lib/rbs/types.rb', line 992 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
1002 1003 1004 |
# File 'lib/rbs/types.rb', line 1002 def ==(other) other.is_a?(Proc) && other.type == type && other.block == block end |
#each_type(&block) ⇒ Object
1044 1045 1046 1047 1048 1049 1050 1051 |
# File 'lib/rbs/types.rb', line 1044 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
1012 1013 1014 1015 1016 |
# File 'lib/rbs/types.rb', line 1012 def free_variables(set = Set[]) type.free_variables(set) block&.type&.free_variables(set) set end |
#hash ⇒ Object
1008 1009 1010 |
# File 'lib/rbs/types.rb', line 1008 def hash self.class.hash ^ type.hash ^ block.hash end |
#map_type_name(&block) ⇒ Object
1053 1054 1055 1056 1057 1058 1059 |
# File 'lib/rbs/types.rb', line 1053 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
1027 1028 1029 |
# File 'lib/rbs/types.rb', line 1027 def sub(s) self.class.new(type: type.sub(s), block: block&.sub(s), location: location) end |
#to_json(*a) ⇒ Object
1018 1019 1020 1021 1022 1023 1024 1025 |
# File 'lib/rbs/types.rb', line 1018 def to_json(*a) { class: :proc, type: type, block: block, location: location }.to_json(*a) end |
#to_s(level = 0) ⇒ Object
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File 'lib/rbs/types.rb', line 1031 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 |