On Dec 22, 2009, at 5:30 PM, Seebs wrote:

> But that doesn't help you in the case where you want to replace empty =
strings
> with '-'.  For that, maybe something like:
>=20
> 	x =3D (x && !x.empty?) ? x : '-'
>=20
> (That assumes x has an empty? predicate, not everything does.)

I've always found the easiest way to replace empty strings is:

x =3D '-' if x.to_s.empty?

Just about everything has a #to_s method, and nil evaluates to an empty =
string, so this will replace x if it is either an empty string *or* if =
it is nil *or* if x is currently not yet defined.

Cheers,

Josh=