From: Ibraheem Ibz Umaru-Mohammed Date: 2002-10-20T05:03:27+09:00 Subject: Re: string[lastchar] -> string? * Szabolcs Szasz [2002-10-19 20:55]: > Ahhh, yes! Thanks! > > I was reading the Pragmatic... book and the String class > doesn't have that 'chr' method there. (And a special thanks > for the negative indexes, which I missed completely...) > I usually just fire up the interpreter, and do something like: ibz@ignoramus:$ irb Reading config file... done. ruby-1.7.3 on i686-pc-linux with irb 0.9(02/07/03) Type 'help' for more information. >>> String.methods.sort ["<", "<=", "<=>", "==", "===", "=~", ">", ">=", "__id__", "__send__", "allocate", "ancestors", "become", "class", "class_eval", "class_variables", "clone", "const_defined?", "const_get", "const_set", "constants", "display", "dup", "eql?", "equal?", "extend", "freeze", "frozen?", "hash", "id", "include?", "included_modules", "inspect", "instance_eval", "instance_method", "instance_methods", "instance_of?", "instance_variables", "is_a?", "kind_of?", "method", "method_defined?", "methods", "module_eval", "name", "new", "nil?", "private_class_method", "private_instance_methods", "private_methods", "protected_instance_methods", "protected_methods", "public_class_method", "public_instance_methods", "public_methods", "respond_to?", "send", "singleton_methods", "superclass", "taint", "tainted?", "to_a", "to_s", "type", "untaint"] >>> Which helps a little when The Book isn't nearby... > > * Szabolcs Szasz [2002-10-19 20:33]: > > > How to elegantly get the last char of a string as a string? > > > Somehow I fear I won't be cacthing girls' attention with this: > > > > > > if ('' << str[str.length-1]) = 'x' > > > str.chop > > > do_things_with(str) > > > ... > > > end > > > [--- snip ---] Also, although you won't be using the code above, you'll find you've forgotten a "=" and a "!" somewhere in there ;) --ibz. --