Skip to content
Browse files

Lazily loading the dictionary

This allows specifying another filename for the dictionary
and not load the default shipped dictionary.
  • Loading branch information...
1 parent 0dcff52 commit a8a72fbc602012b794c9921bd8d1415cf624a657 @jeanregisser jeanregisser committed
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/profanity_filter.rb
View
5 lib/profanity_filter.rb
@@ -36,9 +36,12 @@ class Base
cattr_accessor :replacement_text, :dictionary_file, :dictionary
@@replacement_text = '@#$%'
@@dictionary_file = File.join(File.dirname(__FILE__), '../config/dictionary.yml')
- @@dictionary = YAML.load_file(@@dictionary_file)
class << self
+ def dictionary
+ @@dictionary ||= YAML.load_file(@@dictionary_file)
+ end
+
def banned?(word = '')
dictionary.include?(word.downcase) if word
end

0 comments on commit a8a72fb

Please sign in to comment.
Something went wrong with that request. Please try again.