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.



32
33
34
35
# File 'lib/active_support/inflector/inflections.rb', line 32

def initialize
  @regex_array = []
  super
end

Instance Method Details

#<<(*word) ⇒ Object



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

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

#add(words) ⇒ Object



46
47
48
49
50
51
# File 'lib/active_support/inflector/inflections.rb', line 46

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

#delete(entry) ⇒ Object



37
38
39
40
# File 'lib/active_support/inflector/inflections.rb', line 37

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

#uncountable?(str) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/active_support/inflector/inflections.rb', line 53

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