Class: RBS::Inline::AST::Declarations::ConstantDecl
- Includes:
- ConstantUtil
- Defined in:
- lib/rbs/inline/ast/declarations.rb
Instance Attribute Summary collapse
-
#assertion ⇒ Object
readonly
: Annotations::TypeAssertion?.
-
#comments ⇒ Object
readonly
: AnnotationParser::ParsingResult?.
-
#node ⇒ Object
readonly
: Prism::ConstantWriteNode.
Instance Method Summary collapse
- #constant_name ⇒ Object
-
#initialize(node, comments, assertion) ⇒ ConstantDecl
constructor
A new instance of ConstantDecl.
- #literal_type ⇒ Object
-
#start_line ⇒ Object
: Integer.
- #type ⇒ Object
Methods included from ConstantUtil
Constructor Details
#initialize(node, comments, assertion) ⇒ ConstantDecl
Returns a new instance of ConstantDecl.
184 185 186 187 188 |
# File 'lib/rbs/inline/ast/declarations.rb', line 184 def initialize(node, comments, assertion) #: void @node = node @comments = comments @assertion = assertion end |
Instance Attribute Details
#assertion ⇒ Object (readonly)
: Annotations::TypeAssertion?
179 180 181 |
# File 'lib/rbs/inline/ast/declarations.rb', line 179 def assertion @assertion end |
#comments ⇒ Object (readonly)
: AnnotationParser::ParsingResult?
178 179 180 |
# File 'lib/rbs/inline/ast/declarations.rb', line 178 def comments @comments end |
#node ⇒ Object (readonly)
: Prism::ConstantWriteNode
177 178 179 |
# File 'lib/rbs/inline/ast/declarations.rb', line 177 def node @node end |
Instance Method Details
#constant_name ⇒ Object
234 235 236 |
# File 'lib/rbs/inline/ast/declarations.rb', line 234 def constant_name TypeName.new(name: node.name, namespace: Namespace.empty) end |
#literal_type ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/rbs/inline/ast/declarations.rb', line 211 def literal_type case node.value when Prism::StringNode, Prism::InterpolatedStringNode BuiltinNames::String.instance_type when Prism::SymbolNode, Prism::InterpolatedSymbolNode BuiltinNames::Symbol.instance_type when Prism::RegularExpressionNode, Prism::InterpolatedRegularExpressionNode BuiltinNames::Regexp.instance_type when Prism::IntegerNode BuiltinNames::Integer.instance_type when Prism::FloatNode BuiltinNames::Float.instance_type when Prism::ArrayNode BuiltinNames::Array.instance_type when Prism::HashNode BuiltinNames::Hash.instance_type when Prism::TrueNode, Prism::FalseNode Types::Bases::Bool.new(location: nil) end end |
#start_line ⇒ Object
: Integer
238 239 240 |
# File 'lib/rbs/inline/ast/declarations.rb', line 238 def start_line #: Integer node.location.start_line end |
#type ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/rbs/inline/ast/declarations.rb', line 192 def type if assertion case assertion.type when MethodType, nil # skip else return assertion.type end end if literal = literal_type return literal end Types::Bases::Any.new(location: nil) end |