shelladept
shelladept

Reputation: 127

Ruby Gem "password" Does Not Seem To Install Properly

I am trying to obscure the user input (for example, when inputting a password) for a ruby script. I've tried using both the 'password' gem and 'highline/import' gem, as suggested by this stack overflow article. However, I seems to be having some issues getting the gems to work. When my script is simply:

require 'password'
require 'rubygems'
require 'activesupport'

it outputs the following errors.

C:\Users\username\Desktop>ruby test.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
activesupport (LoadError)
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/password-1.3/lib/password.rb:1:
in `<top (required)>'
        from <internal:lib/rubygems/custom_require>:33:in `require'
        from <internal:lib/rubygems/custom_require>:33:in `rescue in require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from test.rb:1:in `<main>'

I'm not sure that 'activesupport' is necessary; I added it because of the first error line and it hasn't seemed to help. I tried looking at the rdoc information found in the RubyGems Documentation Server and looking up each of the individual lines, but still cannot quite grasp what the problem is. I am using Ruby 1.9.2p180 on a Windows environment. Any insight would be much appreciated. Thank you in advance.

EDIT -- After following the advice of Casper, and installing the highline/import gem (gem install highline), I was able to find the following solution to my ultimate goal of obscuring password input:

require 'rubygems'
require 'highline/import'

username = ask("Enter username:  ") { |x| x.echo = true }
password = ask("Enter password:  ") { |x| x.echo = "*" } #assign false to echo nothing

which produces the following:

Enter username: Joe
Enter password: *********

Thanks Casper!

Upvotes: 3

Views: 1640

Answers (1)

Casper
Casper

Reputation: 34328

You need to load rubygems before you try to load any other gem files. rubygems is what enables your Ruby programs to load other gems with require:

require 'rubygems'
require 'password'
require 'activesupport'

Before you can use the password gem however you need to install it:

gem install ruby-password

Upvotes: 4

Related Questions