I am going to answer my own question as it has been solved. The code is fine when run from a terminal. This problem apparently stems from a limitation in RubyFiddle. Hopefully this question can help someone who comes across the same problem with the RubyFiddle enviornment :)
RubyFiddle issue - NameError: undefined local variable or method 'gets' for #
Question
class SqrrtProg
def hello
puts "Hello! Welcome to the square root program."
puts "\n Please enter a number: "
number = gets
puts number
end
def Sqrrt
end
end
object = SqrrtProg.new
object.hello
I am simply trying to use 'gets' to get user input. I had read that it might be because, by default, gets tries to read information from a file. I have tried name = $stdin.gets and name = &stdin.gets.chomp etc... However, I end up at the same error.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow