Highline , One of Ruby gem !


Highline is one of the rubygems .

Installling gem : –

* First Install Ruby gems

sudo apt-get install rubygems

* Next installing highline gem

sudo gem install highline

Thats all 🙂

It can act as validating tool ..

require “rubygems”

require “highline/import”

ask(“Age?  “, Integer) { |q| q.in = 0..105 }

ask(“Age?  “, Integer) { |q| q.in = 0..105 }
Age?  ewrw
You must enter a valid Integer.
?  12
=> 12

It was nice . It can act as password field in my ruby program 🙂

Small ruby program which ask database username , databasename , password (as password field)


require 'mysql'
require 'rubygems'
require 'highline/import'
print "Enter your Mysql user name :"
user = gets.chomp
pass = ask("Enter the password :" ) { |p| p.echo = "*" }
print "Enter your db name :"
db = gets.chomp
db = Mysql.new("localhost",user,pass,db)
print "Enter the sales amount :"
a = gets.chomp.to_f
print "Enter the sales comission :"
b = gets.chomp.to_f
entry = db.prepare "INSERT INTO salesdetails (sales_amount , sales_comission) VALUES (#{a} , #{b})"
entry.execute
entry.close

No one can find my database passwords from this program 🙂

Advertisements

About sathia

Web developer at cloudmint
This entry was posted in programs. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s