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