File: simple_match.rb

package info (click to toggle)
ruby-mustermann19 0.4.3%2Bgit20160621-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 756 kB
  • ctags: 445
  • sloc: ruby: 7,197; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Mustermann
  # Fakes MatchData for patterns that do not support capturing.
  # @see http://ruby-doc.org/core-2.0/MatchData.html MatchData
  class SimpleMatch
    # @api private
    def initialize(string)
      @string = string.dup
    end

    # @return [String] the string that was matched against
    def to_s
      @string.dup
    end

    # @return [Array<String>] empty array for imitating MatchData interface
    def names
      []
    end

    # @return [Array<String>] empty array for imitating MatchData interface
    def captures
      []
    end

    # @return [nil] imitates MatchData interface
    def [](*args)
      captures[*args]
    end

    # @return [String] string representation
    def inspect
      "#<%p %p>" % [self.class, @string]
    end
  end
end