From: Ollivier Robert Date: 2003-06-13T21:32:57+09:00 Subject: Re: Interactive Console Program with Tab-Completion In article <20030613105433.GB24909@student.ei.uni-stuttgart.de>, Mauricio Fern�ndez wrote: > But bash (and probably tcsh too) uses readline... Nope, tcsh being a BSD licensed program doesn't use the GPL readline. It has its own readline-like code (which existed before readline BTW). Zsh has also its own code for this. To stay in line with the original post, readline is very easy to use in Ruby: -=-=-=- #! /usr/bin/env ruby # # $Id: //depot/src/ruby/dices.rb#1 $ require "readline" class Fixnum def dice(n = 6) res = 0 print " " self.times { dice = rand(n) + 1 print dice.to_s + " " res += dice } puts "" return res end end class String def has_mod? if self =~ /[-+](\d+)$/ then mod = $1.to_i puts " Bonus => #{mod}" return mod else return 0 end end end if $0 == __FILE__ then srand while true do input = Readline::readline("Dice> ", true) if input then input.chomp! input.gsub!(/\s*/, '') bonus = 0 case input when /q/i break when /^(\d+)d(\d+)/ nb = $1.to_i size = $2.to_i res = nb.dice(size) mod = input.has_mod? puts " #{nb} x D#{size} => #{res + mod} (#{res})" when /^d(\d+)/ size = $1.to_i res = 1.dice(size) if res == 1 then puts " **FUMBLE**" elsif res == size puts " **Natural #{size}**" else mod = input.has_mod? puts " D#{size} => #{res + mod} (#{res})" end end else puts "" break end end end -=-=-=- -- Ollivier ROBERT -=- Eurocontrol EEC/ITM -=- roberto@eurocontrol.fr Usenet Canal Historique FreeBSD: The Power to Serve!