From: Robert Klemme Date: 2006-09-11T23:35:34+09:00 Subject: Re: string as nil or empty string? aidy wrote: > Hi, > > With everything in Ruby being an object, should a string be initialised > as an empty string > > e.g. > > a_string = "" > > or nil > > e.g > > a_string = nil It depends on the circumstances. However, an additional note: it may be that you have a misconception about variables in Ruby. Although you named it "a_string" this variable is typeless and it could hold a reference to *any* Ruby object. So a_string "is" not a String as long as it doesn't point to one. And you cannot initialize a String with nil either: irb(main):003:0> String.new nil TypeError: can't convert nil into String from (irb):3:in `initialize' from (irb):3 from :0 irb(main):004:0> String.new "foo" => "foo" HTH Kind regards robert