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


#1



print "Enter a number to square"

gets.chomp n

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


#2

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.


#3

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


#4

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