Class: RSpec::Support::Source::Token
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb
Overview
A wrapper for Ripper token which is generated with ‘Ripper.lex`.
Constant Summary collapse
- CLOSING_TYPES_BY_OPENING_TYPE =
{ :on_lbracket => :on_rbracket, :on_lparen => :on_rparen, :on_lbrace => :on_rbrace, :on_heredoc_beg => :on_heredoc_end }.freeze
- CLOSING_KEYWORDS_BY_OPENING_KEYWORD =
{ 'def' => 'end', 'do' => 'end', }.freeze
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #closed_by?(other) ⇒ Boolean
- #equals_operator? ⇒ Boolean
-
#initialize(ripper_token) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
- #keyword? ⇒ Boolean
- #location ⇒ Object
- #opening? ⇒ Boolean
- #string ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(ripper_token) ⇒ Token
Returns a new instance of Token.
27 28 29 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 27 def initialize(ripper_token) @token = ripper_token.freeze end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
21 22 23 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 21 def token @token end |
Class Method Details
.tokens_from_ripper_tokens(ripper_tokens) ⇒ Object
23 24 25 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 23 def self.tokens_from_ripper_tokens(ripper_tokens) ripper_tokens.map { |ripper_token| new(ripper_token) }.freeze end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
43 44 45 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 43 def ==(other) token == other.token end |
#closed_by?(other) ⇒ Boolean
65 66 67 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 65 def closed_by?(other) delimiter_closed_by?(other) || keyword_closed_by?(other) end |
#equals_operator? ⇒ Boolean
57 58 59 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 57 def equals_operator? type == :on_op && string == '=' end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 49 def inspect "#<#{self.class} #{type} #{string.inspect}>" end |
#keyword? ⇒ Boolean
53 54 55 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 53 def keyword? type == :on_kw end |
#location ⇒ Object
31 32 33 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 31 def location @location ||= Location.new(*token[0]) end |
#opening? ⇒ Boolean
61 62 63 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 61 def opening? opening_delimiter? || opening_keyword? end |
#string ⇒ Object
39 40 41 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 39 def string token[2] end |
#type ⇒ Object
35 36 37 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-support-3.12.0/lib/rspec/support/source/token.rb', line 35 def type token[1] end |