Class: RSpec::Support::Source::Token
- Inherits:
-
Object
- Object
- RSpec::Support::Source::Token
- Defined in:
- 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
-
#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/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/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/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/rspec/support/source/token.rb', line 43 def ==(other) token == other.token end |
#closed_by?(other) ⇒ Boolean
61 62 63 |
# File 'lib/rspec/support/source/token.rb', line 61 def closed_by?(other) closed_by_delimiter?(other) || closed_by_keyword?(other) end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/rspec/support/source/token.rb', line 49 def inspect "#<#{self.class} #{type} #{string.inspect}>" end |
#keyword? ⇒ Boolean
53 54 55 |
# File 'lib/rspec/support/source/token.rb', line 53 def keyword? type == :on_kw end |
#location ⇒ Object
31 32 33 |
# File 'lib/rspec/support/source/token.rb', line 31 def location @location ||= Location.new(*token[0]) end |
#opening? ⇒ Boolean
57 58 59 |
# File 'lib/rspec/support/source/token.rb', line 57 def opening? opening_delimiter? || opening_keyword? end |
#string ⇒ Object
39 40 41 |
# File 'lib/rspec/support/source/token.rb', line 39 def string token[2] end |
#type ⇒ Object
35 36 37 |
# File 'lib/rspec/support/source/token.rb', line 35 def type token[1] end |