Programme.I can't get it

I need a little help in creating a programme that is able keep track of
how much an individual consumes at the bar. It shall separate between
soft drinks, bear and drinks.

So, ask specific questions. If you have several question, it is better
to create separate postings for each posting.

From the wording of your question, I am unsure how much experience you
have in programming, so it would help if you also tell a bit of how deep
your knowledge is in programming in general, and what programming
languages (i.e. not Ruby) you are comfortable with.

class Person
def setName(name)
@name = name
def setAddress(adr)
@address = adr
def getName()
return @name
def getAddrs()
return @address

puts “Enter name of persons”
personel =
select = 0
while (select !=4)
puts “Press 1 to enter drink name”
puts “Press 2 to see the drinks tracked”
puts “Press 3 to show the menu of driks available”
puts “Press 4 to exit the programme”
select = gets.chomp.to_i
if (select==1)
puts “Type what drink do you prefer”
name = gets.chomp
person =
elsif (select == 2)
for i in 0…personel.length()-1
puts “Person number” + i.to_s + " " + personel[i].getName()
elsif (select ==3)
puts “Drink number”
puts “\n” + “Menu”
firstHash =
puts “\n” + firstHash.inspect + “- Drinks”
firstHash[“1”] = “Beer”
firstHash[“2”] = “Whisky”
firstHash[“3”] = “Vodka”
#puts firstHash.values
#puts firstHash.keys
firstHash.each{|key, value| puts “#{key} \t is \t #{value}”}

firstHash =
puts “\n” + firstHash.inspect + “- SoftDrinks”
firstHash[“4”] = “Tea”
firstHash[“5”] = “Coke”
firstHash[“6”] = “Pepsi”

#puts firstHash.values
#puts firstHash.keys
firstHash.each{|key, value| puts “#{key} \t is \t #{value}”}

elsif (select>4)
puts “Not a correct selection”


This is my programme. When I press 1 for typing new drinks i want to put
a condition to be able to type just my drinks available in menu… if
not to put a message with a response like: a don’t have this drink

The program is too hard to read without proper indentation. Please edit
your posting accordingly.

Also, I don’t quite understand your question. Maybe you could also
provide an example dialogue, which you would like to achieve. This would
maybe clarify your problem a bit.

I am a beginner on Ruby … so I’d be thankfull for a liittle help

Hello Mandon Sergiu,

I would put stuff such as:

puts "Enter name of persons"

into your specific class. Give it
some logical name such as “def user_input”
or something like that. You can put this
method then inside of “def initialize”,
or you can also call a specialized method
in your own. I usually call a method
called “run” from within “def initialize”
methods for my larger classes. It helps
my brain remember - .run on an object
and it will run the main-action. (The
rest is mostly for initializing the
class and sanitizing it if necessary)

Also try to indent the code - being a beginner
is no problem but being unable to indent code
is a big problem. :smiley:

class Foo
def hi
puts ‘hi’


class Foo
def hi
puts ‘hi’

Do you see the difference?

It will help other people help you more easily
by the way because that way, they can scan and
spot/identify problems with code much more
rapidly so.

@Robert H.: While I agree, that in a good OO design, the whole
user-interaction should go in its own class (say: Interactor), maybe
this concept is a bit too difficult for a complete beginner in
programming. I have the impression that the OP is still struggling with
putting together basic statements (scripting), so maybe it would be
easier for him to first put the whole dialgoue into the “main program”
(as he already planned) and, if this works, refactor it later by
designing a suitable Interactor class.