John Maclean
1/5/2006 11:35:00 PM
Hey Chaps,
So far so good. I've a menu as shown below. So far by following the "pick axe" I've been able to "hard code" all of my instance variables. I'd like a user to enter his/her details and let his entry specify that variable? Make sense?
#!/usr/bin/ruby
# Thu Jan 5 20:41:45 GMT 2006
# defining a new class for inspectors
class Inpsector
def welcome_inspector
puts "Welcome to the inspector screen"
puts "~~~~~~~ ~~ ~~~ ~~~~~~~~~ ~~~~~~"
print "0:- Inspectors, ready to enter your details?\nq:- quit!\n"
# all we want to do here is collect the inspector's details
end
def initialize(fname, sname, company, dept, team, empno, mobileno)
# these are the instance variables
@fname = fname
@sname = sname
@company = company
@dept = dept
@team = team
@empno = empno
@mobileno = mobileno
end
def insp_choice
print "enter your choice (0,q) : "
ip = $stdin.gets
if ip.chomp! =~ /^[0q]/
case ip
when "0"
print "Entering details capturing session\n"
when "q"
print "about to quit!\n"
end
else
print "poor choice!\n"
end
end
def to_s
"Inpsector: #@fname #@sname #@company, #@dept, #@team, #@empno, #@mobileno\n"
end
end
# todo:- replace this "hard-coded" way of enteringinstance variables
# with those that the user has entered
inspector = Inpsector.new("John", "Mac", "t4m", "insp", "bcv", "666", "07666") #<--------- here
inspector.inspect
inspector.welcome_inspector
inspector.insp_choice
puts inspector
--
John Maclean
MSc (DIC)
07739 171 531