Class: RBS::AST::Ruby::Declarations::ConstantDecl
- Defined in:
- lib/rbs/ast/ruby/declarations.rb
Instance Attribute Summary collapse
-
#constant_name ⇒ Object
readonly
Returns the value of attribute constant_name.
-
#leading_comment ⇒ Object
readonly
Returns the value of attribute leading_comment.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#type_annotation ⇒ Object
readonly
Returns the value of attribute type_annotation.
Attributes inherited from Base
Instance Method Summary collapse
- #comment ⇒ Object
-
#initialize(buffer, constant_name, node, leading_comment, type_annotation) ⇒ ConstantDecl
constructor
A new instance of ConstantDecl.
- #location ⇒ Object
- #name_location ⇒ Object
- #type ⇒ Object
- #type_fingerprint ⇒ Object
Methods included from Helpers::LocationHelper
Methods included from Helpers::ConstantHelper
Constructor Details
#initialize(buffer, constant_name, node, leading_comment, type_annotation) ⇒ ConstantDecl
Returns a new instance of ConstantDecl.
167 168 169 170 171 172 173 |
# 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 ⇒ Object (readonly)
Returns the value of attribute constant_name.
163 164 165 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 163 def constant_name @constant_name end |
#leading_comment ⇒ Object (readonly)
Returns the value of attribute leading_comment.
162 163 164 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 162 def leading_comment @leading_comment end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
164 165 166 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 164 def node @node end |
#type_annotation ⇒ Object (readonly)
Returns the value of attribute type_annotation.
165 166 167 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 165 def type_annotation @type_annotation end |
Instance Method Details
#comment ⇒ Object
209 210 211 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 209 def comment leading_comment&.as_comment end |
#location ⇒ Object
175 176 177 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 175 def location rbs_location(node.location) end |
#name_location ⇒ Object
179 180 181 182 183 184 185 186 |
# 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 ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# 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 ⇒ Object
213 214 215 216 217 218 219 220 |
# 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 |