Class: RBS::Types::Function::Param
- Inherits:
-
Object
- Object
- RBS::Types::Function::Param
- Defined in:
- lib/rbs/types.rb
Instance Attribute Summary collapse
-
#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:) ⇒ Param
constructor
A new instance of Param.
- #map_type ⇒ Object
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type:, name:) ⇒ Param
Returns a new instance of Param.
660 661 662 663 |
# File 'lib/rbs/types.rb', line 660 def initialize(type:, name:) @type = type @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
658 659 660 |
# File 'lib/rbs/types.rb', line 658 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
657 658 659 |
# File 'lib/rbs/types.rb', line 657 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
665 666 667 |
# File 'lib/rbs/types.rb', line 665 def ==(other) other.is_a?(Param) && other.type == type && other.name == name end |
#hash ⇒ Object
671 672 673 |
# File 'lib/rbs/types.rb', line 671 def hash self.class.hash ^ type.hash ^ name.hash end |
#map_type ⇒ Object
675 676 677 678 679 680 681 |
# File 'lib/rbs/types.rb', line 675 def map_type if block_given? Param.new(name: name, type: yield(type)) else enum_for :map_type end end |
#to_json(*a) ⇒ Object
683 684 685 |
# File 'lib/rbs/types.rb', line 683 def to_json(*a) { type: type, name: name }.to_json(*a) end |
#to_s ⇒ Object
687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/rbs/types.rb', line 687 def to_s if name if /\A#{Parser::KEYWORDS_RE}\z/.match?(name) "#{type} `#{name}`" else "#{type} #{name}" end else "#{type}" end end |