On Mon, Nov 4, 2013 at 6:02 PM, Richard Curteis <lists / ruby-forum.com> wrote:
> Ok, thanks. But when I then move on to nameChecker from ageChecker, the
> variable name won't have been passed, do I have to pass it first to
> ageChecker and then onwards or can I simply set them as global variables
> to save time?

I think it's cleaner that each method does only one thing, and have
the code at the upper level call one, then the other, etc.
Check this for example:

def output(age, name)
  weight=96

  print "Age: #{age}\n"
  print "\n"
  print "Name: #{name}\n"
  print "\n"
  print "Weight: #{weight}kg\n"

end

def prompt(message)
  print message
  return gets.chomp
end

def ageChecker(ageInput, age)
  if ageInput == age
   print "Correct age selected.\n"
   return true
  elsif ageInput > age
   print "You are younger than that, you are #{age}\n"
   return false
  else ageInput < age
    print "You are older than that, you are #{age}\n"
    return false
  end

end

def nameChecker(nameInput,name)
  if nameInput == name
    print "Correct\n"
    return true
  else
    print "Wrong name\n"
    return false
  end
end

age = 27
name = "Max"
output(age, name)
begin
    ageInput = Integer(prompt "Enter your age: ")
end while (!ageChecker(ageInput, age))

begin
    nameInput = prompt "Enter your name: "
      nameInput.capitalize!
end while (!nameChecker(nameInput, name))

There are other ways of organizing the code to be cleaner. For
example, have the age and name checkers only do their logic, without
the prints, and have all the output in the top level.

Jesus.