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

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

Instance Method Summary collapse

Methods inherited from Array

#as_json, #deep_dup, #excluding, #extract!, #extract_options!, #fifth, #forty_two, #fourth, #from, #in_groups, #in_groups_of, #including, #inquiry, #second, #second_to_last, #split, #third, #third_to_last, #to, #to_fs, #to_param, #to_query, #to_sentence, #to_xml, wrap

Constructor Details

#initializeUncountables

Returns a new instance of Uncountables.



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

def initialize
  @regex_array = []
  super
end

Instance Method Details

#<<(*word) ⇒ Object



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

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

#add(words) ⇒ Object



46
47
48
49
50
51
# File 'activesupport/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 'activesupport/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 'activesupport/lib/active_support/inflector/inflections.rb', line 53

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