From: AppleII717 Date: 2010-08-18T07:50:07+09:00 Subject: Strange behavior of or condition in loop I don't understand why ruby's "or" acts differently in a loop. This is some code I pulled out of a rails model, expanded the assignments and simulated in IRB (1.8.7 and 1.9.2rc) #simple boolean assignments #Why does this work dirty = false found = true dirty = dirty or found puts dirty.to_s => true #same type of assignments in loop giving meaning to dirty and found #But this does not a = ["score_method", "updated_at"] dirty = false a.each{|attrib| puts dirty.to_s + " in " found = !( /score_method|weight|critical|minimum_value/i =~ attrib ).nil? dirty = dirty or found puts dirty.to_s + " out " + found.to_s } puts dirty.to_s => false #another version with parens around or #But this does a = ["score_method", "updated_at"] dirty = false a.each{|attrib| puts dirty.to_s + " in " found = !( /score_method|weight|critical|minimum_value/i =~ attrib ).nil? dirty = (dirty or found) puts dirty.to_s + " out " + found.to_s } puts dirty.to_s => true I've been doing to additive boolean assignment stuff forever without parens. Guess I just don't understand Ruby.