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(&block) ⇒ Object
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type:, name:) ⇒ Param
Returns a new instance of Param.
663 664 665 666 |
# File 'lib/rbs/types.rb', line 663 def initialize(type:, name:) @type = type @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
661 662 663 |
# File 'lib/rbs/types.rb', line 661 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
660 661 662 |
# File 'lib/rbs/types.rb', line 660 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
668 669 670 |
# File 'lib/rbs/types.rb', line 668 def ==(other) other.is_a?(Param) && other.type == type && other.name == name end |
#hash ⇒ Object
674 675 676 |
# File 'lib/rbs/types.rb', line 674 def hash self.class.hash ^ type.hash ^ name.hash end |
#map_type(&block) ⇒ Object
678 679 680 681 682 683 684 |
# File 'lib/rbs/types.rb', line 678 def map_type(&block) if block Param.new(name: name, type: yield(type)) else enum_for :map_type end end |
#to_json(*a) ⇒ Object
686 687 688 |
# File 'lib/rbs/types.rb', line 686 def to_json(*a) { type: type, name: name }.to_json(*a) end |
#to_s ⇒ Object
690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/rbs/types.rb', line 690 def to_s if name if /\A#{Parser::KEYWORDS_RE}\z/.match?(name) "#{type} `#{name}`" else "#{type} #{name}" end else "#{type}" end end |