> On Nov 7, 2013, at 9:18, Robert Klemme <shortcutter / googlemail.com> wrote:=

>=20
>> On Thu, Nov 7, 2013 at 6:07 PM, Greg Hajdu <lists / ruby-forum.com> wrote:
>> Hello everyone!
>> I'm trying to make a little grocery list to practice. My intention is to
>> make basically an array that you can add to, remove and display items.
>> My problem starts when after a person adds an item to the array for
>> example and the options come up again, instead of going back into the
>> cases the program just quits.
>> It kinda is like a loop where it keeps going around and around.. my
>> program just doesn't wanna do that. :D
>> Could someone explain where I went wrong with my codes?
>>=20
>> list =3D Array.new(0)
>>=20
>> display_proc =3D Proc.new {|x| puts x}
>>=20
>> puts "What would you like to do with your shopping list?"
>>=20
>> def opening_options
>>  puts
>>  puts "--ADD"
>>  puts "--REMOVE"
>>  puts "--CLEAR"
>>  puts "--DISPLAY"
>>  puts "--EXIT"
>>=20
>>  @options =3D gets.chomp.downcase
>> end
>=20
> You need a loop starting here and ...
>=20
>> opening_options
>>=20
>> case @options
>>  when "add"
>>    puts "What item would you like to add?"
>>    add =3D gets.chomp
>>    list << add unless list.include?(add)
>=20
> This line should go away, similarly as all other invocations inside the ca=
se:
>=20
>>    opening_options
>>=20
>>  when "remove"
>>    puts "What item would you like to remove?"
>>    list.each(&display_proc)
>>    remove =3D gets.chomp
>>    list.delete(remove)
>>=20
>>    opening_options
>>=20
>>  when "clear"
>>    puts "Are you sure you want to delete every item from your list?"
>>    puts "--YES/NO"
>>    clear =3D gets.chomp.downcase
>>    case clear
>>      when "yes" || "y"

when "yes", "y"

>>        list.delete_if {true}
>>        opening_options
>>      when "no" || "n"
>>        opening_options
>>      else "ERROR! Unknown command!"
>>    end
>>=20
>>  when "display"
>>    list.each(&display_proc)
>>=20
>>    opening_options
>>=20
>>  when "exit"
>>    system('quit')
>=20
> This won't work. You want to invoke "exit" instead of "system".
>=20
>>  else "ERROR! Unknown command!"
>> end
>=20
> ... ending here.
>=20
> Kind regards
>=20
> robert
>=20
>=20
> --=20
> remember.guy do |as, often| as.you_can - without end
> http://blog.rubybestpractices.com/