On Fri, Nov 16, 2012 at 3:35 PM, Philip Rhoades <phil / pricom.com.au> wrote:
> People,
>
> I have an existing script that looks like:
>
> lots of code
> .
> .
> .
> if ..
>   some lines of code
>   if ..
>     some lines of code
>     if ..
>       some lines of code
>       if ..
>         some lines of code
>         if ..
>           some lines of code
> etc
>
> This makes it difficult to see the overall logic

I can believe *that*.

> so I want to change it to something like:
>
> lots of code
> .
> .
> .
> if ..
>   call something
>   if ..
>     call something
>     if ..
>       call something
>       if ..
>         call something
>         if ..
>           call something
> etc

That does not seem much better to me.  Why do you need such a
structure of code?  Can you be more specific about what you are doing
there?  Maybe a completely different structure of the code is even
better.

> but if I use methods I will have to pass lots of variables or use global
> variables and then it gets clumsy changing everything - is there some way of
> simply calling a block of code and then returning to the same position in
> the nested "ifs"?

I don't think there is.  Unless, maybe, if you declare all local
variables at the beginning of the method, followed by a whole bunch of
Procs which you call where "something" is written.  I doubt though
that this will be more readable.

Kind regards

robert

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