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
- #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.
29 30 31 |
# File 'lib/rspec/support/source/token.rb', line 29 def initialize(ripper_token) @token = ripper_token.freeze end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
23 24 25 |
# File 'lib/rspec/support/source/token.rb', line 23 def token @token end |
Class Method Details
.tokens_from_ripper_tokens(ripper_tokens) ⇒ Object
25 26 27 |
# File '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 Method Details
#==(other) ⇒ Object Also known as: eql?
45 46 47 |
# File 'lib/rspec/support/source/token.rb', line 45 def ==(other) token == other.token end |
#closed_by?(other) ⇒ Boolean
67 68 69 |
# File 'lib/rspec/support/source/token.rb', line 67 def closed_by?(other) delimiter_closed_by?(other) || keyword_closed_by?(other) end |
#equals_operator? ⇒ Boolean
59 60 61 |
# File 'lib/rspec/support/source/token.rb', line 59 def equals_operator? type == :on_op && string == '=' end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/rspec/support/source/token.rb', line 51 def inspect "#<#{self.class} #{type} #{string.inspect}>" end |
#keyword? ⇒ Boolean
55 56 57 |
# File 'lib/rspec/support/source/token.rb', line 55 def keyword? type == :on_kw end |
#location ⇒ Object
33 34 35 |
# File 'lib/rspec/support/source/token.rb', line 33 def location @location ||= Location.new(*token[0]) end |
#opening? ⇒ Boolean
63 64 65 |
# File 'lib/rspec/support/source/token.rb', line 63 def opening? opening_delimiter? || opening_keyword? end |
#string ⇒ Object
41 42 43 |
# File 'lib/rspec/support/source/token.rb', line 41 def string token[2] end |
#type ⇒ Object
37 38 39 |
# File 'lib/rspec/support/source/token.rb', line 37 def type token[1] end |