Class: RSpec::Support::Source::Token Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rspec-support/lib/rspec/support/source/token.rb |
Overview
A wrapper for Ripper token which is generated with Ripper.lex
.
Constant Summary
-
CLOSING_KEYWORDS_BY_OPENING_KEYWORD =
# File 'rspec-support/lib/rspec/support/source/token.rb', line 18{ 'def' => 'end', 'do' => 'end', }.freeze
-
CLOSING_TYPES_BY_OPENING_TYPE =
# File 'rspec-support/lib/rspec/support/source/token.rb', line 11{ :on_lbracket => :on_rbracket, :on_lparen => :on_rparen, :on_lbrace => :on_rbrace, :on_heredoc_beg => :on_heredoc_end }.freeze
Class Method Summary
- .new(ripper_token) ⇒ Token constructor Internal use only
- .tokens_from_ripper_tokens(ripper_tokens) Internal use only
Instance Attribute Summary
- #equals_operator? ⇒ Boolean readonly Internal use only
- #keyword? ⇒ Boolean readonly Internal use only
- #opening? ⇒ Boolean readonly Internal use only
- #token readonly Internal use only
- #opening_delimiter? ⇒ Boolean readonly private Internal use only
- #opening_keyword? ⇒ Boolean readonly private Internal use only
Instance Method Summary
- #==(other) (also: #eql?) Internal use only
- #closed_by?(other) ⇒ Boolean Internal use only
-
#eql?(other)
Alias for #==.
- #inspect Internal use only
- #location Internal use only
- #string Internal use only
- #type Internal use only
- #delimiter_closed_by?(other) ⇒ Boolean private Internal use only
- #keyword_closed_by?(other) ⇒ Boolean private Internal use only
Class Method Details
.tokens_from_ripper_tokens(ripper_tokens)
[ GitHub ]# File 'rspec-support/lib/rspec/support/source/token.rb', line 25
def self.tokens_from_ripper_tokens(ripper_tokens) ripper_tokens.map { |ripper_token| new(ripper_token) }.freeze end
Instance Attribute Details
#equals_operator? ⇒ Boolean
(readonly)
#keyword? ⇒ Boolean
(readonly)
# File 'rspec-support/lib/rspec/support/source/token.rb', line 55
def keyword? type == :on_kw end
#opening? ⇒ Boolean
(readonly)
# File 'rspec-support/lib/rspec/support/source/token.rb', line 63
def opening? opening_delimiter? || opening_keyword? end
#opening_delimiter? ⇒ Boolean
(readonly, private)
# File 'rspec-support/lib/rspec/support/source/token.rb', line 73
def opening_delimiter? CLOSING_TYPES_BY_OPENING_TYPE.key?(type) end
#opening_keyword? ⇒ Boolean
(readonly, private)
# File 'rspec-support/lib/rspec/support/source/token.rb', line 77
def opening_keyword? return false unless keyword? CLOSING_KEYWORDS_BY_OPENING_KEYWORD.key?(string) end
#token (readonly)
[ GitHub ]# File 'rspec-support/lib/rspec/support/source/token.rb', line 23
attr_reader :token
Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]
#closed_by?(other) ⇒ Boolean
# File 'rspec-support/lib/rspec/support/source/token.rb', line 67
def closed_by?(other) delimiter_closed_by?(other) || keyword_closed_by?(other) end
#delimiter_closed_by?(other) ⇒ Boolean
(private)
# File 'rspec-support/lib/rspec/support/source/token.rb', line 82
def delimiter_closed_by?(other) other.type == CLOSING_TYPES_BY_OPENING_TYPE[type] end
#eql?(other)
Alias for #==.
# File 'rspec-support/lib/rspec/support/source/token.rb', line 49
alias_method :eql?, :==
#inspect
[ GitHub ]
#keyword_closed_by?(other) ⇒ Boolean
(private)
# File 'rspec-support/lib/rspec/support/source/token.rb', line 86
def keyword_closed_by?(other) return false unless keyword? return true if other.string == CLOSING_KEYWORDS_BY_OPENING_KEYWORD[string] # Ruby 3's `end`-less method definition: `def method_name = body` string == 'def' && other.equals_operator? && location.line == other.location.line end
#location
[ GitHub ]#string
[ GitHub ]# File 'rspec-support/lib/rspec/support/source/token.rb', line 41
def string token[2] end
#type
[ GitHub ]# File 'rspec-support/lib/rspec/support/source/token.rb', line 37
def type token[1] end