Class: RBS::AST::Ruby::Members::AttributeMember

Inherits:
Base
  • Object
show all
Defined in:
lib/rbs/ast/ruby/members.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#buffer

Instance Method Summary collapse

Methods included from Helpers::LocationHelper

#rbs_location

Constructor Details

#initialize(buffer, node, name_nodes, leading_comment, type_annotation) ⇒ AttributeMember

Returns a new instance of AttributeMember.



656
657
658
659
660
661
662
# File 'lib/rbs/ast/ruby/members.rb', line 656

def initialize(buffer, node, name_nodes, leading_comment, type_annotation)
  super(buffer)
  @node = node
  @name_nodes = name_nodes
  @leading_comment = leading_comment
  @type_annotation = type_annotation
end

Instance Attribute Details

#leading_commentObject (readonly)

Returns the value of attribute leading_comment.



654
655
656
# File 'lib/rbs/ast/ruby/members.rb', line 654

def leading_comment
  @leading_comment
end

#name_nodesObject (readonly)

Returns the value of attribute name_nodes.



652
653
654
# File 'lib/rbs/ast/ruby/members.rb', line 652

def name_nodes
  @name_nodes
end

#nodeObject (readonly)

Returns the value of attribute node.



651
652
653
# File 'lib/rbs/ast/ruby/members.rb', line 651

def node
  @node
end

#type_annotationObject (readonly)

Returns the value of attribute type_annotation.



653
654
655
# File 'lib/rbs/ast/ruby/members.rb', line 653

def type_annotation
  @type_annotation
end

Instance Method Details

#locationObject



670
671
672
# File 'lib/rbs/ast/ruby/members.rb', line 670

def location
  rbs_location(node.location)
end

#name_locationsObject



674
675
676
677
678
# File 'lib/rbs/ast/ruby/members.rb', line 674

def name_locations
  name_nodes.map do |name_node|
    rbs_location(name_node.location)
  end
end

#namesObject



664
665
666
667
668
# File 'lib/rbs/ast/ruby/members.rb', line 664

def names
  name_nodes.map do |node|
    node.unescaped.to_sym
  end
end

#typeObject



680
681
682
# File 'lib/rbs/ast/ruby/members.rb', line 680

def type
  type_annotation&.type
end

#type_fingerprintObject



684
685
686
687
688
689
690
691
692
# File 'lib/rbs/ast/ruby/members.rb', line 684

def type_fingerprint
  [
    "members/attribute",
    self.class.name,
    names.map(&:to_s),
    type_annotation&.type_fingerprint,
    leading_comment&.as_comment&.string
  ]
end