123456789_123456789_123456789_123456789_123456789_

Class: RBS::AST::Ruby::Declarations::ConstantDecl

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
Inherits: RBS::AST::Ruby::Declarations::Base
Defined in: lib/rbs/ast/ruby/declarations.rb

Class Method Summary

Instance Attribute Summary

Base - Inherited

Instance Method Summary

Constructor Details

.new(buffer, constant_name, node, leading_comment, type_annotation) ⇒ ConstantDecl

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 167

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

Instance Attribute Details

#constant_name (readonly)

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 163

attr_reader :constant_name

#leading_comment (readonly)

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 162

attr_reader :leading_comment

#node (readonly)

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 164

attr_reader :node

#type_annotation (readonly)

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 165

attr_reader :type_annotation

Instance Method Details

#comment

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 209

def comment
  leading_comment&.as_comment
end

#location

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 175

def location
  rbs_location(node.location)
end

#name_location

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 179

def name_location
  case node
  when Prism::ConstantWriteNode
    rbs_location(node.name_loc)
  when Prism::ConstantPathWriteNode
    rbs_location(node.target.location)
  end
end

#type

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 188

def type
  return type_annotation.type if type_annotation

  case node.value
  when Prism::IntegerNode
    BuiltinNames::Integer.instance_type
  when Prism::FloatNode
    BuiltinNames::Float.instance_type
  when Prism::StringNode
    BuiltinNames::String.instance_type
  when Prism::TrueNode, Prism::FalseNode
    Types::Bases::Bool.new(location: nil)
  when Prism::SymbolNode
    BuiltinNames::Symbol.instance_type
  when Prism::NilNode
    Types::Bases::Nil.new(location: nil)
  else
    Types::Bases::Any.new(location: nil)
  end
end

#type_fingerprint

[ GitHub ]

  
# File 'lib/rbs/ast/ruby/declarations.rb', line 213

def type_fingerprint
  [
    "decls/constant",
    constant_name.to_s,
    type.to_s,
    leading_comment&.as_comment&.string
  ]
end