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.



645
646
647
648
649
650
651
# File 'lib/rbs/ast/ruby/members.rb', line 645

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.



643
644
645
# File 'lib/rbs/ast/ruby/members.rb', line 643

def leading_comment
  @leading_comment
end

#name_nodesObject (readonly)

Returns the value of attribute name_nodes.



641
642
643
# File 'lib/rbs/ast/ruby/members.rb', line 641

def name_nodes
  @name_nodes
end

#nodeObject (readonly)

Returns the value of attribute node.



640
641
642
# File 'lib/rbs/ast/ruby/members.rb', line 640

def node
  @node
end

#type_annotationObject (readonly)

Returns the value of attribute type_annotation.



642
643
644
# File 'lib/rbs/ast/ruby/members.rb', line 642

def type_annotation
  @type_annotation
end

Instance Method Details

#locationObject



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

def location
  rbs_location(node.location)
end

#name_locationsObject



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

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

#namesObject



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

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

#typeObject



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

def type
  type_annotation&.type
end

#type_fingerprintObject



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

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