1
我在項目中使用gem gmail
來使用終端登錄帳戶; 操作系統是Linux(debian whezzy)。如何使用ruby中的gets/chomp登錄帳戶而不在終端顯示字符串?
以下是運行的代碼一個例子:
[email protected]:/home/user/project$ ruby --version
**ruby 2.1.0p0 (2013-12-25 revision 44422) [i686-linux]**
[email protected]:/home/user/project$ ruby login.rb
===========
Gmail login
===========
please give your username (without @gmail.com) and password
(they will not be show, so please type first, press RET, type password)
username: # waiting for username...
password: # waiting for password...
的問題是:使用gets.chomp
,提示符顯示它的用戶名/密碼的字符串。我不想要這個;我希望有一種類似於UNIX系統帳戶登錄的功能,即提示等待輸入,但不顯示爲用戶輸入。
4篇一些參考文獻,我把使用的代碼:
def respond_to(&block)
puts "==========="
puts "Gmail login"
puts "==========="
puts "please give your username (without @gmail.com) and password (they will not be show, so please type first, press RET, type password)"
Gmail.connect("#{gets.chomp}@gmail.com", "#{gets.chomp}") do |client|
if client.logged_in?
puts "\n#{client.username} sucessfully logged in!\n"
yield(false, client)
else
true
end
end
end
我跟着一些提示在zetcode,但不具有光的射線。
謝謝!