Class: Meteor::Core::Util::PatternCache

Inherits:
Object
  • Object
show all
Defined in:
lib/meteor/core/util/pattern_cache.rb

Overview

Pattern Cache Class (パターン・キャッシュ クラス)

Constant Summary collapse

@@regex_cache =
Hash.new

Class Method Summary collapse

Class Method Details

.get(regex) ⇒ Regexp .get(regex, option) ⇒ Regexp

get pattern (パターンを取得する)

Overloads:

  • .get(regex) ⇒ Regexp

    Returns pattern (パターン).

    Parameters:

    • regex (String)

      regular expression (正規表現)

    Returns:

    • (Regexp)

      pattern (パターン)

  • .get(regex, option) ⇒ Regexp

    Returns pattern (パターン).

    Parameters:

    • regex (String)

      regular expression (正規表現)

    • option (Fixnum)

      option of Regex (オプション)

    Returns:

    • (Regexp)

      pattern (パターン)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/meteor/core/util/pattern_cache.rb', line 29

def self.get(*args)
  case args.length
    when ONE
      # get_1(args[0])
      if @@regex_cache[args[0].to_sym]
        @@regex_cache[args[0].to_sym]
      else
        @@regex_cache[args[0].to_sym] = Regexp.new(args[0], Regexp::MULTILINE)
      end
    when TWO
      # get_2(args[0], args[1])
      if @@regex_cache[args[0].to_sym]
        @@regex_cache[args[0].to_sym]
      else
        @@regex_cache[args[0].to_sym] = Regexp.new(args[0], args[1])
      end
    else
      raise ArgumentError
  end
end