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

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

Overview

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

Constant Summary

@@regex_cache =
Hash.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (PatternCache) initialize

intializer (イニシャライザ)



3067
3068
# File 'lib/meteor.rb', line 3067

def initialize
end

Class Method Details

+ (Regexp) get(regex) + (Regexp) get(regex, option)

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

Overloads:

  • + (Regexp) get(regex)

    Pattern (パターン)

    Parameters:

    • regex (String)

      regular expression (正規表現)

    Returns:

    • (Regexp)

      pattern (パターン)

  • + (Regexp) get(regex, option)

    Pattern (パターン)

    Parameters:

    • regex (String)

      regular expression (正規表現)

    • option (Fixnum)

      option of Regex (オプション)

    Returns:

    • (Regexp)

      pattern (パターン)



3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
# File 'lib/meteor.rb', line 3081

def self.get(*args)
  case args.length
    when ONE
      #get_1(args[0])
      if @@regex_cache[args[0].to_sym] then
        @@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] then
        @@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