On Jul 22, 2013, at 6:50 PM, "Talal B." <lists / ruby-forum.com> wrote:

> Hi guys,
>=20
> I'm new to ruby and I'm writing simple programs to help my =
understanding
> of ruby. I wrote the program below and I would like to know if you =
guys
> could recommend a while loop to use before the if statement so the
> program doesn't end until a key is pressed? I want it to keep running
> until the user quits. Also does anyone think I can make the program
> better?class OhmsLaw
>  def initialize(voltage, current, resistance)
>    @voltage =3D voltage
>    @current =3D current
>    @resistance =3D resistance
>  end
>  def voltageNil
>    @current * resistance
>  end
>  def currentNil
>    @voltage / @resistance
>  end
>  def resistanceNil
>    @voltage / @current
>  end
>  def to_s
>    "String representation of OhmsLaw V: #{@voltage}, I: #{@current}, =
R:
> #{@resistance}"
>  end
>=20
>    #This will make these variables accessoable from outside
>    #of the class
>  attr_accessor :voltage, :current, :resistance
>  #solve4Current can be used for :currentNil as  an alias for it
>  alias :solve4Current :currentNil
> end
>=20
> #created a new object called solve that will take V,I,R as inputs
> solve =3D OhmsLaw.new(9.0, nil, 2)
> #attr_accessor allows us to change voltage of 9 to 16 volts from
> #outside of the class
> solve.voltage =3D 16
>=20
> if solve.voltage =3D=3D nil
>  puts solve.voltageNil
> elsif solve.current =3D=3D nil
>  puts solve.solve4Current
> else
>  puts solve.resistanceNil
> end
>=20
> puts "#{solve}"
>=20
> --=20
> Posted via http://www.ruby-forum.com/.
>=20

Welcome!

I'm of two minds here:

1) writing a REPL (read-eval-print loop) is a worthy exercise in itself, =
so yes
2) if you just want to work with your class, you can use irb as your =
REPL, so maybe not yet