On Nov 18, 11:45=A0pm, shadowfirebird <shadowfireb... / gmail.com> wrote:
> It appears that my mail client is having trouble -- hence the blank
> message bodies. =A0Sorry about that.
>
> Flebber, if you have a simple application and aren't coding to learn
> about OOP, it may be that you simply don't need classes. =A0In Ruby,
> they are optional.
>
> You should think of classes as a way of wrapping functionality and
> data together. =A0You've not told us anything about your data, or how
> complex foo() is, so I'm not sure we can give you more concrete
> suggestions. =A0 But if you start thinking about how the data needs to
> be organised, and what operations the data needs to be able to perform
> on itself, then either some classes will "pop out" -- or they won't,
> and you'll know that this program does not need to be OOP.
>
> With regard to your option selection block, I would personally put
> that functionality into foo, and just pass foo a "mode" variable, so:
>
> loop do
> =A0 =A0 mode, data =3D getinput()
> =A0 =A0 break if (mode =3D=3D "quit")
>
> =A0 =A0 foo(mode, data)
> end
>
> I'm not sure why your pseudocode asks for input twice and then runs
> foo() twice, but presumably there is a good reason.
>
> Likewise, we don't know whether you plan to gather input using a GUI
> (which would involve an event-driven approach) or at the command line,
> for instance (which would allow much simpler code).

> Is this sort of thing what you mean?
>
> # The main loop
> def main
>    loop do
>       puts "Please choose an option:"
>       puts " [1] Option1"
>       puts " [2] Option2"
>       puts " [3] Option3"
>       opt =3D nil
>
>       # A primitive event handler
>       case gets.to_i
>       when 1
>          opt =3D Option1.new
>       when 2
>          opt =3D Option2.new
>       when 3
>          opt =3D Option3.new
>       end
>
>       # Check if a valid option was entered
>       if opt
>          opt.run
>       else
>          puts "Error: please enter valid option."
>       end
>    end
> end

Yes but this is how initially I started to write my code but then had
the thought that since my calculations weren't computer intensive. So
I thought why not calculate all options first and show what valid
options exist to the user rather than looping around the options
trying to find a valid option. Is this a good way to go.

> I'm not sure why your pseudocode asks for input twice and then runs
> foo() twice, but presumably there is a good reason.


> Likewise, we don't know whether you plan to gather input using a GUI
> (which would involve an event-driven approach) or at the command line,
> for instance (which would allow much simpler code).

I ask after the program has identified there is a valid option and the
user wants to select it, it is valid data but only names and
identifiers that will be recorded in a database not relevant to
whether the calculation is valid.

i will be using a command line solution. My calculations aren't
complex they simply pass through  a small formula and check whether a
ratio resolves to true. If both true then its a valid option the user
can choose.