From: Derek Smith Date: 2009-08-20T08:49:58+09:00 Subject: Re: if defined on var Sebastian Hungerecker wrote: > Am Mittwoch 19 August 2009 04:22:18 schrieb Derek Smith: >> My goal is to see if a table exists by testing the var holding the data >> is true/defined or not. Will you help? > > true and defined are two very different things. Take this snippet as an > example: > > x = 42 > y = false > z = nil > > Here the variables x, y and z are defined. The variables a, b and > foobarbaz > are not. In short: once you assign a value to a variable that variable > is > defined - no matter whether that value was true or not. If you want to > check > whether the value a variable holds is true or not, do that. Don't use > defined?. > In your case you can just do if table_exists which even reads more > naturally. > > HTH, > Sebastian Hey Seb, Your advice is always welcome and respected. But Iam still confused, see below. The table derek does NOT exist of course. table_exists = db.execute("select name from sqlite_master where type='table' and tbl_name='derek'") if table_exists p "yes", "#{table_exists}" end if table_exists == "" p "yes" else p "no" end __OUTPUT__ $ ruby mail_log_miner.rb "yes" "" "no" With a table that does exist using same if clauses. ruby mail_log_miner.rb "yes" "lines" "no" -- Posted via http://www.ruby-forum.com/.