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.
177 178 179 180 181 182 183 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 177 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.
173 174 175 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 173 def constant_name @constant_name end |
#leading_comment ⇒ Object (readonly)
Returns the value of attribute leading_comment.
172 173 174 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 172 def leading_comment @leading_comment end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
174 175 176 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 174 def node @node end |
#type_annotation ⇒ Object (readonly)
Returns the value of attribute type_annotation.
175 176 177 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 175 def type_annotation @type_annotation end |
Instance Method Details
#comment ⇒ Object
219 220 221 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 219 def comment leading_comment&.as_comment end |
#location ⇒ Object
185 186 187 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 185 def location rbs_location(node.location) end |
#name_location ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 189 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
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 198 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
223 224 225 226 227 228 229 230 |
# File 'lib/rbs/ast/ruby/declarations.rb', line 223 def type_fingerprint [ "decls/constant", constant_name.to_s, type.to_s, leading_comment&.as_comment&.string ] end |