From: Henrik Horneber Date: 2004-09-23T16:54:40+09:00 Subject: whitespace string only Hi! What's the best way to test if a string only consists of whitespaces and newlines? best I could come up with is class String def is_whitespace_only? strings_to_test = split("\n") whitespace = /^\s+$/ is_whitespace_only = true strings_to_test.each{ |str| unless whitespace.match(str) or str.empty? is_whitespace_only = false break end } is_whitespace_only end end But somehow I think there should be a better way to do it. Any ideas? Is it okay to add such methods to class String itself? Any advices appreciated. regards, Henrik