Masking user input passwords I have a method that accepts user input. Additionally, it masks passwords then the input is a password. It also bypasses the prompt of if an env variable supplies the needed input.

Apparently, my code needs refactoring, but how?

def self.gets(args)
  array = []
  args.each do |arg|
    print "#{arg.to_s.capitalize}: "
    if ENV['AWESOMEAPP_'+arg.to_s.upcase]
      array.push ENV['AWESOMEAPP_'+arg.to_s.upcase]
    else
      if arg.to_s=~/password/
        array.push STDIN.noecho(&amp;:gets).chomp
      else
        array.push STDIN.gets.chomp
      end
    end
    print "\n"
  end
  array
end
After reading @user1777136 s answer, I came up with this

module Awesome
  # Has methods that are similar to but extended versions                                                        
  # of core ruby methods                                                                                         
  module Extensions
    # Get multipe inputs from user                                                                               
    # Masks passwords if detected                                                                                
    # Bypasses prompt when ENV variables present                                                                 
    def self.mgets(names)
      names.map do |name|
        sgets(name)
      end
    end

    # single gets                                                                                                
    def self.sgets(name)
      print "#{name.to_s.capitalize}: "
      return env_sgets(name) if ENV['AWESOME_' + name.to_s.upcase]
      return secure_sgets if name.match?(/password/)
      STDIN.gets.chomp
    end

    # get from env variable                                                                                      
    def self.env_sgets(name)
      ENV['AWESOME_' + name.to_s.upcase]
    end

    # secure gets from stdin                                                                                     
    def self.secure_sgets
      STDIN.noecho(&amp;:gets).chomp
    end
  end
end