[Ruby] How to use standard output in conditional branching

When I tried to input standard input using gets like when solving an algorithm problem, I got the following error

$ ruby enc_main.rb new
Traceback (most recent call last):
        2: from enc_main.rb:12:in `<main>'
        1: from enc_main.rb:12:in `gets'
enc_main.rb:12:in `gets': No such file or directory @ rb_sysopen - new (Errno::ENOENT)

Workaround

I solved it by using the gets method using $ stdin in the code below.

if ARGV[0] == "new"
  puts "What's Name?"
  name = $stdin.gets

Referenced documents

$ stdin (Ruby 2.7.0 Reference Manual) Active engineers explain how to use stdin in Ruby [for beginners] | TechAcademy Magazine

Recommended Posts

[Ruby] How to use standard output in conditional branching
How to use Ruby return
Ruby: How to use cookies
Learning Ruby with AtCoder 12 How to use standard output properly (p / puts / print)
How to use Lombok in Spring
How to iterate infinitely in Ruby
How to use Ruby on Rails
How to install Bootstrap in Ruby
[Ruby] How to use any? Method
How to use InjectorHolder in OpenAM
How to use classes in Java?
How to use Ruby inject method
Multilingual Locale in Java How to use Locale
How to get date data in Ruby
How to use custom helpers in rails
[Ruby on Rails] How to use CarrierWave
How to use named volume in docker-compose.yml
Ruby standard output
Ruby length, size, count How to use
How to use Docker in VSCode DevContainer
How to use MySQL in Rails tutorial
[Ruby] How to use slice for beginners
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
How to use environment variables in RubyOnRails
Ruby: CSV :: How to use Table Note
Understand in 5 minutes !! How to use Docker
How to use credentials.yml.enc introduced in Rails 5.2
From terminal to Ruby (standard input / output)
How to use ExpandableListView in Android Studio
(Memo) How to solve dummy output in Ubuntu 20.04
How to color code console output in Eclipse
[Java] How to get and output standard input
I want to use arrow notation in Ruby
[Rails] How to use select boxes in Ransack
[Ruby] How to use gsub method and sub method
How to use "sign_in" in integration test (RSpec)
Output of how to use the slice method
How to use JQuery in js.erb of Rails6
[Ruby on Rails] How to install Bootstrap in Rails
How to build the simplest blockchain in Ruby
[Ruby on Rails] How to use session method
[ruby] How to receive values from standard input?
[Rails] How to use PostgreSQL in Vagrant environment
How to implement Pagination in GraphQL (for ruby)
[Ruby basics] How to use the slice method
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity