From: Alexander McMillan Date: 2011-12-11T19:48:25+09:00 Subject: Re: Learn To Program (Chris Pine) - Building and Sorting Array --_adc8cca5-b620-4fa8-9f02-e3e9e3714dc3_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable It is one thing reading Chris Pines book and then jumping into rails but=2C= Christ Pines book is dated=2C also it only deals with "a little" Ruby. Bef= ore learning Rails I would suggest you first learn how to create the "page"= =2C widgets and so on. You should try the gem RXRuby to learn to create pas= sword boxes etc. RXRuby may have come with your Ruby installation.Why I say= you should learn how to create "page" and widgets is simple=2C you will ha= ve to do this with Rails.The "page" is basically pages that appear on the s= creen=2C these could be graphics=2C or form type pages.There are a few begi= nners Ruby lessons on oldkingjames.org that may help you with your Ruby as = these are for complete beginners to programming itself. > Date: Sat=2C 10 Dec 2011 08:02:02 +0900 > From: emekapatrick@gmail.com > Subject: Re: Learn To Program (Chris Pine) - Building and Sorting Array > To: ruby-talk@ruby-lang.org >=20 > Hi John=2C >=20 > Thanks so much for getting back to me and for your kind words. Really=20 > big encouragement for someone just starting out and feeling a wee bit=20 > lost at times. As well=2C I must say the willingness of people in the Rub= y=20 > community to offer help has really been pretty amazing. >=20 > John W Higgins wrote in post #1036028: > > Good Day Emeka=2C > > > > On Fri=2C Dec 9=2C 2011 at 12:47 PM=2C Emeka Patrick > > wrote: > > > >> Hi Robert=2C > >> > >> Thanks so much for getting back to me on this much appreciated. Some > >> questions in-line below. > >> > > > > Thank you for at least attempting to figure things out. Very refreshing > > in > > contrast to some of the questions that people pose here........ >=20 > Thanks a bunch. Want to make sure I truly understand how and why things=20 > work when they do (or when they don't!) >=20 > >> > > >> >> '. Basically=2C I don't think I get what I'm making response equal = to=2C is > >> >> it an empty string=2C 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. > >> > >> So basically with !=3D and =3D=3D I'm asking if what precedes the expr= ession > >> is either "different from" or "the same as" whatever follows. Am I > >> correct? > >> > > > > That would be correct. > > >=20 > Great! >=20 > > > >> Also=2C I still don't think I fully understand the empty string. In th= e > >> two lines of code... > >> > >> if response !=3D '' > >> responses.push response > >> > >> ...am I doing something like "Is what was entered for the variable > >> response different from an empty string? If so then push whatever stri= ng > >> is entered to the end of the responses array." > >> > > > > That would also be correct. One other small item=2C normally code is > > indented > > (Ruby standard is 2 spaces) another level inside a control statement > > (if/while/else and such) to make it slightly easier to read the code. >=20 > I've been trying to do this as well as line up certain elements of code= =2C=20 > but keep slipping in my enthusiasm to get it all out there. Def. need to= =20 > try harder to keep it up. What about using Tab to indent=2C is there any= =20 > reason that might be frowned upon? Btw=2C I'm using TextMate. >=20 > > > > Taking your earlier work > > > > if response !=3D '' > > responses.push response > > else > > puts responses.sort > > break > > end > > > > > > It seemed to me that the logical way to enter this code would be > >> > >> responses =3D [] > >> response =3D gets.chomp > >> > >> while response !=3D '' > >> responses.push response > >> end > >> > >> puts responses.sort > >> > > > > Actually very close here. Your problem is that you end up in an endless > > loop because you never get another entry from the user. > > > > This should do the trick > > > > responses =3D [] > > response =3D gets.chomp > > > > while response !=3D '' > > responses.push response > > response =3D gets.chomp # get another line from the user > > end > > > > puts responses.sort > > >=20 > Oh wow=2C ok=2C I think I get it. This is super clean too. Much nicer tha= n=20 > what I originally had. Now=2C one last question=2C I need response =3D=20 > gets.chomp in the first instance just to define what the variable stands= =20 > for=2C correct? It's not actually until the second instance where I'm=20 > soliciting input from the user=2C or actually is it more so the first=20 > instance both defines the variable and solicits input from the user=20 > while the second instance solicits input in a continuous loop until it=20 > gets broken=2C i.e. when a user enters an empty string? >=20 > > But very very close for someone just picking up programming. You appear > > to > > at least grasp the basic mechanics of working through a problem! > > > > Best of luck to you! > > > > John >=20 > Thanks again John=2C super helpful! Almost done with chapter 9=2C "Writin= g=20 > Your Own Methods". Only 100 pages to go! >=20 > On another note=2C do you have any recommendations for Ruby resources=20 > and/or a path to take towards Ruby On Rails? I'm planning on finishing=20 > Learning to Program=2C doing the Rails for Zombies courses=2C then divin= g=20 > into Michael Hartl's tutorial for Rails 2.3 and then reading Agile=20 > Development with Rails 3rd edition. Thoughts? Btw=2C I'm learning 2.3 as = a=20 > site I had built was in 2.3.8 and I figure I should learn that first and= =20 > then later learn 3 / 3.1. >=20 > Thanks=2C >=20 > Emeka >=20 > --=20 > Posted via http://www.ruby-forum.com/. >=20 = --_adc8cca5-b620-4fa8-9f02-e3e9e3714dc3_--