@private A wrapper for Ripper token which is generated with `Ripper.lex`.
# File lib/rspec/core/source/token.rb, line 26 def initialize(ripper_token) @token = ripper_token.freeze end
# File lib/rspec/core/source/token.rb, line 22 def self.tokens_from_ripper_tokens(ripper_tokens) ripper_tokens.map { |ripper_token| new(ripper_token) }.freeze end
# File lib/rspec/core/source/token.rb, line 42 def ==(other) token == other.token end
# File lib/rspec/core/source/token.rb, line 60 def closed_by?(other) closed_by_delimiter?(other) || closed_by_keyword?(other) end
# File lib/rspec/core/source/token.rb, line 48 def inspect "#<#{self.class} #{type} #{string.inspect}>" end
# File lib/rspec/core/source/token.rb, line 52 def keyword? type == :on_kw end
# File lib/rspec/core/source/token.rb, line 30 def location @location ||= Location.new(*token[0]) end
# File lib/rspec/core/source/token.rb, line 56 def opening? opening_delimiter? || opening_keyword? end
# File lib/rspec/core/source/token.rb, line 38 def string token[2] end
# File lib/rspec/core/source/token.rb, line 34 def type token[1] end
# File lib/rspec/core/source/token.rb, line 75 def closed_by_delimiter?(other) other.type == CLOSING_TYPES_BY_OPENING_TYPE[type] end
# File lib/rspec/core/source/token.rb, line 79 def closed_by_keyword?(other) return false unless other.keyword? other.string == CLOSING_KEYWORDS_BY_OPENING_KEYWORD[string] end
# File lib/rspec/core/source/token.rb, line 66 def opening_delimiter? CLOSING_TYPES_BY_OPENING_TYPE.key?(type) end
# File lib/rspec/core/source/token.rb, line 70 def opening_keyword? return false unless keyword? CLOSING_KEYWORDS_BY_OPENING_KEYWORD.key?(string) end