class RBS::AST::Ruby::Declarations::ConstantDecl
Attributes
node
[R]
node
type_annotation
[R]
Annotations::NodeTypeAssertion?
Public Class Methods
(Buffer, TypeName, node, CommentBlock?, Annotations::NodeTypeAssertion?) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/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
Calls superclass method
RBS::AST::Ruby::Declarations::Base::new
Public Instance Methods
() → AST::Comment?
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/declarations.rb, line 209 def comment leading_comment&.as_comment end
Returns the comment content extracted from the leading comment block
() → Location
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/lib/rbs/ast/ruby/declarations.rb, line 175 def location rbs_location(node.location) end
() → Location
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/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
() → Types::t
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/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
Returns the type of the constant
-
When type_anntoation is given, it returns the type from the annotation.
-
When
type_annotationis not given, it returns infered type from the right-hand-side of the constant assignment -
Or it returns
untypedtype
() → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/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