On Fri, Dec 9, 2011 at 9:58 AM, Emeka Patrick <emekapatrick / gmail.com> wrot=
e:
> Super new to programming (1 week or so) and working through 'Learn to
> Program' to get an understanding of Ruby before moving on to trying my
> hand at Ruby on Rails. That being said I was having a bit of trouble
> working through the first "A Few Things To Try" in section 8.3.

Welcome to the world of Ruby!

> So, we're asked to write a program that asks us to type as many words as
> we want (one word per line, continuing until we just press 'ENTER' on an
> empty line) and then repeats the words back to us in an alphabetical
> order.
>
> After working on this for a bit, I came up with this program (see
> below), which seems to work. However I really want to understand
> everything and I don't think I fully get why it allows me to add things
> to the array and doesn't start to sort until I press enter on a blank
> line when i say if response !=3D ' ' , but not when I make response =3D=
=3D '
> '. Basically, I don't think I get what I'm making response equal to, is
> it an empty string, or?

!=3D and =3D=3D are tests and not assignments.  If you exchange =3D=3D for =
!=3D
you also need to exchange branches of the if else end construct.

> Any help would be appreciated, as well as better ideas on how to go
> about writing this program.
>
> Thanks a ton,
>
> Emeka
>
> responses =3D []
>
> while true
> response =3D gets.chomp
>
> if response !=3D ''
> responses.push response
>
> else
> =A0puts responses.sort
> =A0break
> end
> end

As an additional task you could try to rewrite your program to not use
an endless loop ("while true") but rather use the fact that the input
was the empty string as termination condition for the loop.  This
would be more natural than breaking out of the loop.  The result will
look something like this:

responses =3D []
???

while ???
  responses.push response
end

puts responses.sort

Where "???" are placeholders your code.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/