Class: RBS::Types::Function::Param
- Inherits:
-
Object
- Object
- RBS::Types::Function::Param
- Defined in:
- lib/rbs/types.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(type:, name:, location: nil) ⇒ Param
constructor
A new instance of Param.
- #map_type(&block) ⇒ Object
- #to_json(state = _ = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type:, name:, location: nil) ⇒ Param
Returns a new instance of Param.
877 878 879 880 881 |
# File 'lib/rbs/types.rb', line 877 def initialize(type:, name:, location: nil) @type = type @name = name @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
875 876 877 |
# File 'lib/rbs/types.rb', line 875 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
874 875 876 |
# File 'lib/rbs/types.rb', line 874 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
873 874 875 |
# File 'lib/rbs/types.rb', line 873 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
883 884 885 |
# File 'lib/rbs/types.rb', line 883 def ==(other) other.is_a?(Param) && other.type == type && other.name == name end |
#hash ⇒ Object
889 890 891 |
# File 'lib/rbs/types.rb', line 889 def hash self.class.hash ^ type.hash ^ name.hash end |
#map_type(&block) ⇒ Object
893 894 895 896 897 898 899 |
# File 'lib/rbs/types.rb', line 893 def map_type(&block) if block Param.new(name: name, type: yield(type), location: location) else enum_for :map_type end end |
#to_json(state = _ = nil) ⇒ Object
901 902 903 |
# File 'lib/rbs/types.rb', line 901 def to_json(state = _ = nil) { type: type, name: name }.to_json(state) end |
#to_s ⇒ Object
905 906 907 908 909 910 911 912 913 914 915 |
# File 'lib/rbs/types.rb', line 905 def to_s if name if name.match?(/\A[a-zA-Z0-9_]+\z/) "#{type} #{name}" else "#{type} `#{name}`" end else "#{type}" end end |