On 5 June 2012 17:06, Vinay B. <lists / ruby-forum.com> wrote:

> Hey guys!
>
> I'm a hobbyist Rubyist, and this is my very first script/program in
> Ruby:
> https://gist.github.com/2875930
>
> (This is my very first programming endeavor as well.)
>
> I understand that it might be ugly as hell. Would love to hear any
> comments from you all.
>
> Oh, and I am a major amateur in making methods communicate with
> each-other. I can write stand-alone methods, but none wherein a method
> initiates another method.
>

The lack of functions makes this very difficult to read and give advise on.
Maybe if you split the code up a bit more, and then repost it, I could have
another look. As a general rule if have lots of end statements next to each
other (as you do at the bottom of your code) it's a good indication that
you should be extracting that functionality out into different functions.

For example, the whole section that starts with "filelines.each", would be
best extracted to a function called "parse_filelines". The functionality
doesn't change, but your code suddenly becomes much more readable.
Similarly, each case statement should probably be extracted to a different
function (probably multiple functions). Your while loop could then be
reduced to about 10 lines of code and it would be very clear what each case
statement does, by the name of function it calls.

Does that make sense?
Jeremy Walker


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