0

is gets nil?

this line in my code w = gets.gsub(/[[:space:]]/, '') raised an error at Playgrounds "undefined method `gsub' for nil:" is gets nil? why irb accepts the code? thanks

8th May 2017, 4:55 PM
sehrguey
4 Réponses
+ 2
I tryed it and it worked for me in the playground.
8th May 2017, 5:10 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
One thing you have to know about the playground is that you have to enter all input at once, before the code run. You have to enter it in the popup that appears, each in its line. So, it is not a good idea to make codes that ask for input inside a loop in the playground. Because, you will eventually run out of inputs and the next iteration will throw an error. Maybe, that's what is happening in your case.
9th May 2017, 9:38 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
# Enter a word for processing or "bye" to end the program: ugly --> uglies # Enter a word for processing or "bye" to end the program: ..\Playground\:54:in `block in <class:Ending>': undefined method `gsub' for nil:NilClass (NoMethodError) from ..\Playground\:50:in `loop' from ..\Playground\:50:in `<class:Ending>' from ..\Playground\:1:in `<main>' this is today's try maybe you tried just the line and it worked OK for you in my code the line is a part in a loop for an input for me it's all above the head all I can say is that terminal and playground do not see things with the same eye thanks for your answer
9th May 2017, 4:59 PM
sehrguey
0
thank you for the explanation, now I know that the playground is not a proper place for playing with code.
10th May 2017, 2:03 PM
sehrguey