Sha256: 6adc98a01c6de57010b67eee75af3f6310258c586a45c0b642918daa7114eeda

Contents?: true

Size: 882 Bytes

Versions: 28

Compression:

Stored size: 882 Bytes

Contents

#!/usr/bin/env ruby
#
# Sample Ruby source file.

require 'getoptlong'

HELP = 'Usage: <%= name %>.rb [-h] [-t times] who
-h        To print this help screen
-t times  The number of times to great
who       To name the person to great'

# Great a given person.
# - who: the person to great.
# - times: number of times to great (defaults to 1).
def hello(who, times=1)
  times.times do
    puts "Hello #{who}!"
  end
end

# parse command line
if __FILE__ == $0
  who = 'World'
  times = 1
  opts = GetoptLong.new(
    ["--help",  "-h", GetoptLong::NO_ARGUMENT],
    ["--times", "-t", GetoptLong::REQUIRED_ARGUMENT]
  )
  opts.each do |opt, arg|
    case opt
    when '--help'
      puts HELP
      exit 0
    when '--times'
      times = arg.to_i
    end
  end
  if ARGV.length > 1
    puts HELP
    exit 0
  end
  if ARGV.length == 1
    who = ARGV[0]
  end
  hello(who, times)
end

Version data entries

28 entries across 14 versions & 1 rubygems

Version Path
bee-0.12.2 egg/source/source.rb
bee-0.12.2 egg/script/script.rb
bee-0.12.1 egg/source/source.rb
bee-0.12.1 egg/script/script.rb
bee-0.12.0 egg/source/source.rb
bee-0.12.0 egg/script/script.rb
bee-0.11.4 egg/script/script.rb
bee-0.11.4 egg/source/source.rb
bee-0.11.3 egg/script/script.rb
bee-0.11.3 egg/source/source.rb
bee-0.11.2 egg/script/script.rb
bee-0.11.2 egg/source/source.rb
bee-0.11.1 egg/script/script.rb
bee-0.11.1 egg/source/source.rb
bee-0.11.0 egg/source/source.rb
bee-0.11.0 egg/script/script.rb
bee-0.10.2 egg/source/source.rb
bee-0.10.2 egg/script/script.rb
bee-0.10.1 egg/script/script.rb
bee-0.10.1 egg/source/source.rb