-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday 05 January 2002 02:34 pm, Michael Joner wrote: > On Sat, 05 Jan 2002 19:06:58 GMT HarryO <harryo / zipworld.com.au> wrote: > > That only happens if the method doesn't change the object. So, ... > > "hello".capitalize! # => "Hello" > > whereas > > "Hello".capitalize! # => nil > > because it was already capitalised. > So what would the code be if you aren't sure whether the object has been > capitalized or not? There is no need for such code, unless you need to test to make sure that your in-place (aka destructive) method actually did *something*. I'm asking, is there a reason you would do something like: new_string = old_string.capitalize! except to use new_string as a truth value? If old_string does capitalize, you've only succeeded in aliasing it. If old_string is already capitalized, new_string is nil. This is very useful in a boolean context like: if (old_string.capitalize!) p "thanks for the input, mr. cummings." # e.e. cummings, that is else p "Thanks for the input." # the capitalists? end If you want to alias old_string even if capitalize! was not done, then you probably want something like (remembering some good advice about side-effects and keeping our statements simple): old_string.capitalize! new_string = old_string.dup Then we can deal with old_string and new_string separately, and they'll both be capitalized... Otherwise, if we really want to maintain our original old_string and make all our changes to new_string and new_string only, we'll just use: new_string = old_string.capitalize Clear as mud now, right? *grin* --Michael C. Libby { x (at) ichimunki (dot) com } ================================================================ | "even monkeys fall from trees" :: "saru mo ki kara ochiru" | | | | public key at http://www.ichimunki.com/public.key. | |Fingerprint: D946 FE20 79EE 2109 161B FAFB E029 56F4 A330 AA73| ================================================================ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8N3bg4ClW9KMwqnMRAkIYAKCjLgumvqg+MwvnXSeoAKhgDGpXTgCeNtZs vmirqUrnexA3QgmkrrMdDMs= =8fSp -----END PGP SIGNATURE-----