19 how to print the result of a gets.chomp entry into a method


print "Enter a number to square"

gets.chomp n

def square(n) n ** 2 end
    puts square(n)


Passing information to methods is done by passing arguments, not by printing.
So you would gets the value, possibly convert it to the appropriate type, and then call the method with the value as an argument.


usually you would want to store a response into a variable, that way it will store to your db and be accessible when needed.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.