Class: RBS::Inline::AST::Annotations::BlockType
- Defined in:
- lib/rbs/inline/ast/annotations.rb
Overview
‘@rbs &block: METHOD-TYPE` or `@rbs &block: ? METHOD-TYPE`
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
: String?.
-
#name ⇒ Object
readonly
: Symbol?.
-
#type ⇒ Object
readonly
: Types::Block?.
-
#type_source ⇒ Object
readonly
: String.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(tree, source) ⇒ BlockType
constructor
A new instance of BlockType.
Constructor Details
#initialize(tree, source) ⇒ BlockType
Returns a new instance of BlockType.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/rbs/inline/ast/annotations.rb', line 214 def initialize(tree, source) @tree = tree @source = source annotation = tree.nth_tree!(1) if name = annotation.nth_token?(1) @name = name[1].to_sym end optional = annotation.nth_token?(3) if type_token = annotation.nth_token?(4) block_src = type_token[1] proc_type = ::RBS::Parser.parse_type("^" + block_src, require_eof: true) rescue RBS::ParsingError if proc_type.is_a?(Types::Proc) @type = Types::Block.new( type: proc_type.type, required: !optional, self_type: proc_type.self_type ) end @type_source = block_src else @type = nil @type_source = "" end if comment = annotation.nth_tree(5) @comment = comment.to_s end end |
Instance Attribute Details
#comment ⇒ Object (readonly)
: String?
209 210 211 |
# File 'lib/rbs/inline/ast/annotations.rb', line 209 def comment @comment end |
#name ⇒ Object (readonly)
: Symbol?
205 206 207 |
# File 'lib/rbs/inline/ast/annotations.rb', line 205 def name @name end |
#type ⇒ Object (readonly)
: Types::Block?
207 208 209 |
# File 'lib/rbs/inline/ast/annotations.rb', line 207 def type @type end |
#type_source ⇒ Object (readonly)
: String
211 212 213 |
# File 'lib/rbs/inline/ast/annotations.rb', line 211 def type_source @type_source end |