Hi,
Am Montag, 17. Sep 2007, 04:19:53 +0900 schrieb Ari Brown:
> On Sep 16, 2007, at 3:10 PM, Alex Shulgin wrote:
>> Please show me the Ruby way!
>
> Maybe you could try this:
>
> a = gets.chomp #=> "My name is Ari"
> words = a.split(/ /) #=> ["My", "name", "is", "Ari"]
This isn't actually elaborate as it doesn't recognize tabs
or multiple whitespace. It is even longer than
words = gets.split
With no argument or nil, String#split uses $; what normally
is nil, too. Then, split uses something like %r/[ \t\n\r\v\f]+/.
You may easily read whole lines; they shouldn't become too
long. Reading the first word before the user typed enter
would need to tweak terminal settings. Not worth the effort
in most cases.
Bertram
--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de