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.
582 583 584 585 |
# File 'lib/rbs/types.rb', line 582 def initialize(type:, name:) @type = type @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
580 581 582 |
# File 'lib/rbs/types.rb', line 580 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
579 580 581 |
# File 'lib/rbs/types.rb', line 579 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
587 588 589 |
# File 'lib/rbs/types.rb', line 587 def ==(other) other.is_a?(Param) && other.type == type && other.name == name end |
#hash ⇒ Object
593 594 595 |
# File 'lib/rbs/types.rb', line 593 def hash self.class.hash ^ type.hash ^ name.hash end |
#map_type ⇒ Object
597 598 599 600 601 602 603 |
# File 'lib/rbs/types.rb', line 597 def map_type if block_given? Param.new(name: name, type: yield(type)) else enum_for :map_type end end |
#to_json(*a) ⇒ Object
605 606 607 |
# File 'lib/rbs/types.rb', line 605 def to_json(*a) { type: type, name: name }.to_json(*a) end |
#to_s ⇒ Object
609 610 611 612 613 614 615 616 617 618 619 |
# File 'lib/rbs/types.rb', line 609 def to_s if name if /\A#{Parser::KEYWORDS_RE}\z/.match?(name) "#{type} `#{name}`" else "#{type} #{name}" end else "#{type}" end end |