Ruby - Better way to write out this code, to minimize copy/paste bulk : I am right now designing a user interface for a menu project and I was wondering if there is a better way for me to go about doing this, because the way I have this done is extremely tedious. I tried using a for loop such as:

for i in 0..8
    i=i
end
for k in 0..7
    k=k
end

if @selection==i && @unlock==k && $switches[(what do I do here?)]==?????
do thing

So, to explain what this menu does is as such: whenever the user presses the Y key on their keyboard it will turn a selected function off. So, if you're currently highlighted over @selection==1 and you pressed the Y key, you would turn the corresponding switch at that specific location off. @unlock is just used as a way of saying, unless this global boolean is set to true, THEN you can press Y and turn this switch on or off.

      if @selection==0
        pbSEPlay("buzzer",65) if @unlock0==true
      end
      if @selection==1 && $switches[310]==true && @unlock1==true
        $switches[310]=false
        pbSEPlay("BW2MenuChoose",65)
        @graphics["switch"].setBitmap("Graphics/Pictures/Input Map/switchoff")
      elsif @selection==1 && $switches[310]==false && @unlock1==true
        $switches[310]=true
        pbSEPlay("BW2MenuChoose",65)
        @graphics["switch"].setBitmap("Graphics/Pictures/Input Map/switchon")
      end
      if @selection==2 && $switches[300]==true && @unlock2==true
        $switches[300]=false
        pbSEPlay("BW2MenuChoose",65)
        @graphics["switch"].setBitmap("Graphics/Pictures/Input Map/switchoff")
      elsif @selection==2 && $switches[300]==false && @unlock2==true
        $switches[300]=true
        pbSEPlay("BW2MenuChoose",65)
        @graphics["switch"].setBitmap("Graphics/Pictures/Input Map/switchon")
      end
      if @selection==3 && $switches[339]==true && @unlock3==true
        $switches[339]=false
        pbSEPlay("chooseSE",65) if @unlock3==true
        @graphics["switch"].setBitmap("Graphics/Pictures/Input Map/switchoff")
      elsif @selection==3 && $switches[339]==false && @unlock3==true
        $switches[339]=true
        pbSEPlay("chooseSE",65) if @unlock3==true
        @graphics["switch"].setBitmap("Graphics/Pictures/Input Map/switchon")
      end
      if @selection==4 && $switches[338]==true && @unlock4==true
        $switches[338]=false
        pbSEPlay("BW2MenuChoose",65) if @unlock4==true
        @graphics["switch"].setBitmap("Graphics/Pictures/Input Map/switchoff")
      elsif @selection==4 && $switches[338]==false && @unlock4==true
        $switches[338]=true
        pbSEPlay("BW2MenuChoose",65) if @unlock4==true
        @graphics["switch"].setBitmap("Graphics/Pictures/Input Map/switchon")
      end
      if @selection==5
        $switches[330]=false if @unlock5==true && $switches[330]==true
        $switches[330]=true if @unlock5==true && $switches[330]==false
        pbSEPlay("BW2MenuChoose",65) if @unlock5==true
      end
      if @selection==6
        $switches[318]=false if @unlock6==true && $switches[318]==true
        $switches[318]=true if @unlock6==true && $switches[318]==false
        pbSEPlay("BW2MenuChoose",65) if @unlock6==true
      end
      if @selection==7
        pbSEPlay("buzzer",65) if @unlock7==true
      end