From: roob noob Date: 2012-05-18T10:38:33+09:00 Subject: Re: what is going wrong here? The case of the noob not understanding initialize First let me thank you for all of the help you have been :). It is much appreciated, I find that the more I learn Ruby and start to get a grasp on the basics, the more questions I end up having that are not easily answered by prepackaged guides, ie: I need to start asking people. Second, how does this look? These are snippets from a class that estimates password entropy. Before I was using instance variables for @entropy_bits and calling methods like in my previous examples, now I am trying to use inject I think I at least come close to doing it right. My program does work anyway. def estimate_password_entropy(password) evaluate_entropy = [ contains_dictionary_word?(password), contains_special_character?(password), contains_upcase_character?(password), contains_lowcase_character?(password), contains_number?(password), length_estimated_entropy(password) ] puts evaluate_entropy.to_s entropy_bits = evaluate_entropy.inject(:+) end def contains_dictionary_word?(password) entropy_bits = 0 passed_dictionary_test = true File.open("#{RELATIVEPATH}/data/dictionary") do |dictionary| while line = dictionary.gets passed_dictionary_test = false and break if password.include?(line.chop) end entropy_bits = 6 if passed_dictionary_test and password.length > 4 end return entropy_bits end #all other tests fit the following pattern def contains_special_character?(password) entropy_bits = 0 special_characters = %w{ ~ ! @ # $ % ^ & * ( ) _ - + = \{ [ ] | \ : ; " ' < , > . ? / \} } special_characters.each do |special_character| if password.include?(special_character) then entropy_bits = 1.5 and break end end return entropy_bits end -- Posted via http://www.ruby-forum.com/.