Push Inputted Words

I'm trying to make a program that gets you to input words and when you
press enter with nothing typed it sorts them alphabetically. My code
right now is:

words=[]
while words!=''
words.push gets
end
if words==''
  words.sort
end

It runs and asks for words. I assume that it is pushing them into the
array but it isn't stopping and sorting them when there is nothing
inputted by the user. Hope I gave enough information.

As always thanks in advance,
Scott Andrechek

···

--
Posted via http://www.ruby-forum.com/.

I'm now using this:

words=[]
word = 'any'
while word!= ''
  words.push gets
  word= gets.chomp
end
puts
puts words.sort

but as you might notice this code will skip every second word to find a
matching variable for word :S

-Scott

···

--
Posted via http://www.ruby-forum.com/.

Or to void instance variables:

words = []
while (word = gets.chomp) != ''
  words.push word
end
puts words.sort

sascha

···

--
Posted via http://www.ruby-forum.com/.

Try this

John

···

On Sun, Jun 28, 2009 at 9:59 PM, Scott Andrechek <scottandrechek@gmail.com>wrote:

I'm now using this:

words=
word = 'any'
while word!= ''
words.push gets
word= gets.chomp
end
puts
puts words.sort

but as you might notice this code will skip every second word to find a
matching variable for word :S

Try this

137478’s gists · GitHub

John

It workes great I just don't what @ does :S [would to know for future
reference and use : ) ]

-Scott

···

--
Posted via http://www.ruby-forum.com/\.

Scott,

···

On Sun, Jun 28, 2009 at 10:52 PM, Scott Andrechek <scottandrechek@gmail.com>wrote:

> Try this
>
> 137478’s gists · GitHub
>
> John

It workes great I just don't what @ does :S [would to know for future
reference and use : ) ]

Denotes an instance variable. Allows you to set the variable in the function
and still access it within the while loop.

John

Hi,

···

Am Montag, 29. Jun 2009, 14:52:24 +0900 schrieb Scott Andrechek:

> Try this
>
> 137478’s gists · GitHub
>
> John

It workes great I just don't what @ does :S [would to know for future
reference and use : ) ]

  Programming Ruby: The Pragmatic Programmer's Guide

Is it asked too much that you read the first seven paragraphs
before posting?

Bertram

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Is it asked too much that you read the first seven paragraphs
before posting?

Bertram

Is it too much for you to ignore a thread that you find objectionable?

John