Class: ActiveSupport::Inflector::Inflections::Uncountables

Inherits:
Array
  • Object
show all
Defined in:
lib/active_support/inflector/inflections.rb

Instance Method Summary collapse

Methods inherited from Array

#as_json, #deep_dup, #extract_options!, #fifth, #forty_two, #fourth, #from, #in_groups, #in_groups_of, #inquiry, #second, #second_to_last, #split, #sum, #third, #third_to_last, #to, #to_formatted_s, #to_param, #to_query, #to_sentence, #to_xml, #without, wrap

Constructor Details

#initializeUncountables

Returns a new instance of Uncountables.



35
36
37
38
# File 'lib/active_support/inflector/inflections.rb', line 35

def initialize
  @regex_array = []
  super
end

Instance Method Details

#<<(*word) ⇒ Object



45
46
47
# File 'lib/active_support/inflector/inflections.rb', line 45

def <<(*word)
  add(word)
end

#add(words) ⇒ Object



49
50
51
52
53
54
# File 'lib/active_support/inflector/inflections.rb', line 49

def add(words)
  words = words.flatten.map(&:downcase)
  concat(words)
  @regex_array += words.map { |word| to_regex(word) }
  self
end

#delete(entry) ⇒ Object



40
41
42
43
# File 'lib/active_support/inflector/inflections.rb', line 40

def delete(entry)
  super entry
  @regex_array.delete(to_regex(entry))
end

#uncountable?(str) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/active_support/inflector/inflections.rb', line 56

def uncountable?(str)
  @regex_array.any? { |regex| regex.match? str }
end