This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -w | |
#system('ls -la') #=> outputs the output of that command | |
#system('skype') #open skype using system command. | |
#http://www.dreamsyssoft.com/ruby-scripting-tutorial/loops-tutorial.php | |
require 'optparse' | |
options = {:name => nil, :age => nil} | |
parser = OptionParser.new do|opts| | |
opts.banner = "Usage: ruby_linux.rb [options]" | |
opts.on('-n', '--name name', 'Name') do |name| | |
options[:name] = name; | |
end | |
opts.on('-a', '--age age', 'Age') do |age| | |
options[:age] = age; | |
end | |
opts.on('-h', '--help', 'Displays Help') do | |
puts opts | |
exit | |
end | |
end | |
parser.parse! | |
if options[:name] == nil | |
print 'Enter Name: ' | |
options[:name] = gets.chomp | |
end | |
if options[:age] == nil | |
print 'Enter Age: ' | |
options[:age] = gets.chomp | |
end | |
sayHello = 'Hello ' + options[:name] + ', ' | |
if Integer(options[:age]) == 100 | |
sayAge = 'You are already 100 years old!' | |
elsif Integer(options[:age]) < 100 | |
sayAge = 'You will be 100 in ' + String(100 - Integer(options[:age])) + ' years!' | |
else | |
sayAge = 'You turned 100 ' + String(Integer(options[:age]) - 100) + ' years ago!' | |
end | |
puts sayHello + sayAge |
No comments:
Post a Comment