Группа :: Разработка/Ruby
Пакет: ruby-doc-extra
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: ProgrammingRuby-1.8.1.patch
Скачать
Скачать
diff -urN ProgrammingRuby/latex/book.tip ProgrammingRuby.build/latex/book.tip
--- ProgrammingRuby/latex/book.tip 2001-01-23 23:59:41 +0200
+++ ProgrammingRuby.build/latex/book.tip 2004-03-24 19:25:56 +0200
@@ -32,11 +32,11 @@
%
\newgray{COVERRULEGRAY}{.7}
-\def\PPTitle{\psline[linewidth=4pt,linecolor=COVERRULEGRAY]{-}(0,-2pt)(6in,-2pt)
- \scalebox{1 2}{\Huge Programming Ruby}}
+\def\PPTitle{\psline[linewidth=4pt,linecolor=COVERRULEGRAY]{-}(0pt,-2pt)(6in,-2pt)
+ \scalebox{1}[2]{\Huge Programming Ruby}}
{\pagestyle{empty}
- \hbox{}\vspace{1in}{\raggedleft\PPTitle\vfill}
+ \hbox{}\vspace{1in}{\raggedleft\PPTitle{}\vfill}
\pagebreak
\mbox{}\vfill
\pagebreak
@@ -50,11 +50,11 @@
\mbox{}
\vspace{1in}\PPTitle\\[4pt]
-\scalebox{1 1.5}{\LARGE The Pragmatic Programmer's Guide}\\[3ex]
+\scalebox{1}[1.5]{\LARGE The Pragmatic Programmer's Guide}\\[3ex]
\vspace{.2in}
\gray
-\scalebox{1 1.25}{\Large David Thomas}\\[1em]
-\scalebox{1 1.25}{\Large Andrew Hunt}
+\scalebox{1}[1.25]{\Large David Thomas}\\[1em]
+\scalebox{1}[1.25]{\Large Andrew Hunt}
\vfil
\newlength{\AWlen}
diff -urN ProgrammingRuby/latex/classes.tip ProgrammingRuby.build/latex/classes.tip
--- ProgrammingRuby/latex/classes.tip 2001-01-23 23:59:41 +0200
+++ ProgrammingRuby.build/latex/classes.tip 2004-03-24 19:25:56 +0200
@@ -624,7 +624,7 @@
\begin{ruby}
class Test
- puts "Type of self = #{self.type}"
+ puts "Type of self = #{self.class}"
puts "Name of self = #{self.name}"
end
\end{ruby}
@@ -685,7 +685,7 @@
def Module::doc(aClass)
# If we're passed a class or module, convert to string
# ('<=' for classes checks for same class or subtype)
- aClass = aClass.name if aClass.type <= Module
+ aClass = aClass.name if aClass.class <= Module
@@docs[aClass] || "No documentation for #{aClass}"
end
end
@@ -917,7 +917,7 @@
what is ``self''?
\begin{ruby}[comment]
- self.type
+ self.class
\end{ruby}
At the top level, we're executing code in the context of some
diff -urN ProgrammingRuby/latex/code/objectInfo.rb ProgrammingRuby.build/latex/code/objectInfo.rb
--- ProgrammingRuby/latex/code/objectInfo.rb 2001-01-23 23:58:45 +0200
+++ ProgrammingRuby.build/latex/code/objectInfo.rb 2004-03-24 19:25:56 +0200
@@ -1,3 +1,3 @@
def objectInfo(anObject)
- "#{anObject.type}: '#{anObject}'"
+ "#{anObject.class}: '#{anObject}'"
end
diff -urN ProgrammingRuby/latex/code/precDef.rb ProgrammingRuby.build/latex/code/precDef.rb
--- ProgrammingRuby/latex/code/precDef.rb 2001-01-23 23:58:45 +0200
+++ ProgrammingRuby.build/latex/code/precDef.rb 2004-03-24 19:25:56 +0200
@@ -2,24 +2,24 @@
Precision.append_features(NegativeNumber)
def NegativeNumber.induced_from(n)
- if (n.type == Fixnum)
+ if (n.class == Fixnum)
return NegativeNumber.new(-(n.abs))
end
- if (n.type == Float)
+ if (n.class == Float)
return NegativeNumber.new(-1.0 * (n.abs))
end
raise "Can't convert " + n.type.to_s
end
def Float.induced_from(n)
- if (n.type == NegativeNumber)
+ if (n.class == NegativeNumber)
return n.getFloat
end
super.induced_from(n)
end
def Integer.induced_from(n)
- if (n.type == NegativeNumber)
+ if (n.class == NegativeNumber)
return n.getInt
end
super.induced_from(n)
diff -urN ProgrammingRuby/latex/language.tip ProgrammingRuby.build/latex/language.tip
--- ProgrammingRuby/latex/language.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/language.tip 2004-03-24 20:04:26 +0200
@@ -244,7 +244,7 @@
\begin{ruby}[comment]
12.34
--.1234e2
+-0.1234e2
1234e-2
\end{ruby}
@@ -1130,7 +1130,7 @@
end
\end{ruby}
-\begin{ruby}[comment]
+\begin{ruby}[comment,synerr]
!- class Holder
!- @@var = 99
!- def Holder.var=(val)
diff -urN ProgrammingRuby/latex/lib_cgi.tip ProgrammingRuby.build/latex/lib_cgi.tip
--- ProgrammingRuby/latex/lib_cgi.tip 2001-03-12 05:47:49 +0200
+++ ProgrammingRuby.build/latex/lib_cgi.tip 2004-03-24 19:25:56 +0200
@@ -48,7 +48,7 @@
\begin{figure}
\begin{verbatim}
-\begin{ruby}[rawop]
+\begin{ruby}[rawop,norun]
!!-code/cgi.rb
\end{ruby}
\end{verbatim}
diff -urN ProgrammingRuby/latex/lib_delegate.tip ProgrammingRuby.build/latex/lib_delegate.tip
--- ProgrammingRuby/latex/lib_delegate.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/lib_delegate.tip 2004-03-24 19:25:56 +0200
@@ -71,7 +71,7 @@
end
def [](*n)
val = super(*n)
- case val.type
+ case val.class
when Numeric; val/12.0
else; val.collect {|i| i/12.0}
end
@@ -88,7 +88,7 @@
!- end
!- def [](*n)
!- val = super(*n)
-!- case val.type
+!- case val.class
!- when Numeric; val/12.0
!- else; val.collect {|i| i/12.0}
!- end
diff -urN ProgrammingRuby/latex/lib_net_http.tip ProgrammingRuby.build/latex/lib_net_http.tip
--- ProgrammingRuby/latex/lib_net_http.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/lib_net_http.tip 2004-03-24 19:25:56 +0200
@@ -6,7 +6,7 @@
\index{Network protocols!HTTP}
\begin{usage}
- \begin{ruby}
+ \begin{ruby}[norun]
require 'net/http'
h = Net::HTTP.new('www.pragmaticprogrammer.com', 80)
diff -urN ProgrammingRuby/latex/lib_net_telnet.tip ProgrammingRuby.build/latex/lib_net_telnet.tip
--- ProgrammingRuby/latex/lib_net_telnet.tip 2001-03-12 05:47:49 +0200
+++ ProgrammingRuby.build/latex/lib_net_telnet.tip 2004-03-24 19:25:56 +0200
@@ -8,7 +8,7 @@
Connect to a \CF{localhost}, run the ``date'' command, and disconnect.
- \begin{ruby}[comment]
+ \begin{ruby}[comment,norun]
require 'net/telnet'
tn = Net::Telnet.new({})
@@ -22,7 +22,7 @@
library calls; this block is called whenever data becomes
available from the host.
- \begin{ruby}
+ \begin{ruby}[norun]
require 'net/telnet'
tn = Net::Telnet.new({}) { |str| print str }
@@ -35,7 +35,7 @@
Get the time from an NTP server.%
\index{NTP (Network Time Protocol)}
- \begin{ruby}
+ \begin{ruby}[norun]
require 'net/telnet'
!- tn = Net::Telnet.new('Host' => 'ntp0.cornell.edu',
!+ tn = Net::Telnet.new('Host' => 'time.nonexistent.org',
diff -urN ProgrammingRuby/latex/lib_socket.tip ProgrammingRuby.build/latex/lib_socket.tip
--- ProgrammingRuby/latex/lib_socket.tip 2001-11-26 21:07:51 +0200
+++ ProgrammingRuby.build/latex/lib_socket.tip 2004-03-24 20:12:24 +0200
@@ -117,7 +117,7 @@
\begin{method}{getaddress}{IPSocket.getaddress( \obj{hostName} )
\returns{\obj{aString}}}{A}
Returns the dotted-quad IP address of \obj{hostName}.
- \begin{ruby}[comment]
+ \begin{ruby}[comment,norun]
!- require 'socket'
a = IPSocket.getaddress('www.ruby-lang.org')
a
@@ -152,7 +152,7 @@
\begin{class}{TCPSocket}{IPSocket}{}\def\self{\obj{sock}}%
\index{Network protocols!TCP}
- \begin{ruby}[comment]
+ \begin{ruby}[comment,norun]
!- require 'socket'
t = TCPSocket.new('localhost', 'ftp')
t.gets
@@ -600,7 +600,7 @@
contains the address family, port number, host name, host IP
address, protocol family, socket type, and protocol.
- \begin{ruby}
+ \begin{ruby}[norun]
!- require 'socket'
!+ for line in Socket.getaddrinfo('www.microsoft.com', 'http')
!+ puts line.join(", ")
@@ -652,7 +652,7 @@
family, the port (or nil), and the host name or IP address. If a
fourth element is present and not \nil, it will be used as the host name.
Returns a canonical hostname (or address) and port number as an array.
- \begin{ruby}[comment]
+ \begin{ruby}[comment,norun]
!- require 'socket'
a = Socket.getnameinfo(["AF_INET", '23', 'www.ruby-lang.org'])
a
diff -urN ProgrammingRuby/latex/Makefile ProgrammingRuby.build/latex/Makefile
--- ProgrammingRuby/latex/Makefile 2001-01-23 23:59:41 +0200
+++ ProgrammingRuby.build/latex/Makefile 2004-03-24 20:13:08 +0200
@@ -32,9 +32,9 @@
# Take a .tip and produce a .tex
-RUBY = /tc/usr/ruby161/bin/ruby
+RUBY = /usr/bin/ruby
-FILTER = $(RUBY) -I $(UTIL) $(UTIL)/code.rb -name $< | pic -t
+FILTER = LANG=POSIX $(RUBY) -I $(UTIL) $(UTIL)/code.rb -name $< | pic -t
%.txi: %.tip $(UTIL)/code.rb
cat $< | $(FILTER) >$@
diff -urN ProgrammingRuby/latex/ref_c_file__stat.tip ProgrammingRuby.build/latex/ref_c_file__stat.tip
--- ProgrammingRuby/latex/ref_c_file__stat.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/ref_c_file__stat.tip 2004-03-24 20:08:52 +0200
@@ -265,7 +265,7 @@
permission bit set, \CONST{false} if it doesn't or
if the operating system doesn't support this feature.
\begin{ruby}[comment]
- File.stat("/usr/sbin/lpc").setgid?
+ File.stat("/sbin/netreport").setgid?
\end{ruby}
\end{method}
diff -urN ProgrammingRuby/latex/ref_c_file.tip ProgrammingRuby.build/latex/ref_c_file.tip
--- ProgrammingRuby/latex/ref_c_file.tip 2001-03-12 05:47:49 +0200
+++ ProgrammingRuby.build/latex/ref_c_file.tip 2004-03-24 20:05:47 +0200
@@ -156,7 +156,7 @@
must be set correctly).
``\CF{\sd}\obj{user}'' expands to the named user's home
directory.
- \begin{ruby}[comment]
+ \begin{ruby}[comment,norun]
File.expand_path("~oracle/bin")
File.expand_path("../../bin", "/tmp/x")
\end{ruby}
@@ -176,7 +176,7 @@
\begin{ruby}[comment]
File.ftype("testfile")
File.ftype("/dev/tty")
- File.ftype("/tmp/.X11-unix/X0")
+ File.ftype("/dev/null")
\end{ruby}
\end{method}
diff -urN ProgrammingRuby/latex/ref_c_float.tip ProgrammingRuby.build/latex/ref_c_float.tip
--- ProgrammingRuby/latex/ref_c_float.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/ref_c_float.tip 2004-03-24 19:25:56 +0200
@@ -72,7 +72,7 @@
\begin{method}{nan?}{\self.nan? \returns{\bool}}{A}
Returns \CONST{true} if \self{} is an invalid IEEE
floating point number.
- \begin{ruby}[comment*]
+ \begin{ruby}[comment*,norun]
a = -1.0
a.nan?
a = Math.log(a)
diff -urN ProgrammingRuby/latex/ref_c_module.tip ProgrammingRuby.build/latex/ref_c_module.tip
--- ProgrammingRuby/latex/ref_c_module.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/ref_c_module.tip 2004-03-24 19:25:56 +0200
@@ -20,7 +20,7 @@
# ...
end
end
- Mod.type
+ Mod.class
Mod.constants
Mod.instance_methods
\end{ruby}
@@ -467,7 +467,7 @@
if String === o
print "Can't add Picky to a String\n"
else
- print "Picky added to ", o.type, "\n"
+ print "Picky added to ", o.class, "\n"
super
end
end
diff -urN ProgrammingRuby/latex/ref_c_object.tip ProgrammingRuby.build/latex/ref_c_object.tip
--- ProgrammingRuby/latex/ref_c_object.tip 2001-11-26 21:07:52 +0200
+++ ProgrammingRuby.build/latex/ref_c_object.tip 2004-03-24 19:25:56 +0200
@@ -399,6 +399,8 @@
Returns an array representation of \self. For
objects of class \C{Object} and others that don't explicitly
override the method, the return value is an array containing \CONST{self}.
+ This method is deprecated in Ruby 1.7 and later because only objects which really
+ behave as \C{Array} are permitted to respond to this message.
\begin{ruby}[comment]
self.to_a
"hello".to_a
@@ -413,7 +415,7 @@
context of Ruby programs returns ``main.''
\end{method}
- \begin{method}{type}{\self.type \returns{\obj{aClass}}}{A}
+ \begin{method}{class}{\self.class \returns{\obj{aClass}}}{A}
Returns the class of \self{}.
\end{method}
diff -urN ProgrammingRuby/latex/ref_c_range.tip ProgrammingRuby.build/latex/ref_c_range.tip
--- ProgrammingRuby/latex/ref_c_range.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/ref_c_range.tip 2004-03-24 19:25:56 +0200
@@ -113,17 +113,6 @@
Synonym for \CIM{Range.end}.
\end{method}
- \begin{method}{length}{\self.length \returns{\obj{anInteger}}}{A}
- Returns the number of objects in \self.
- \begin{ruby}[comment]
- (1..10).length
- (1...10).length
- \end{ruby}
- \end{method}
-
- \begin{method}{size}{\self.size \returns{\obj{anInteger}}}{A}
- Synonym for \CIM{Range.length}.
- \end{method}
\end{methods}
\end{class}
% LocalWords: succ OddNum FixNum Fixnum xxxxx attr aRange bool anObject
diff -urN ProgrammingRuby/latex/ref_c_string.tip ProgrammingRuby.build/latex/ref_c_string.tip
--- ProgrammingRuby/latex/ref_c_string.tip 2001-10-10 00:16:59 +0300
+++ ProgrammingRuby.build/latex/ref_c_string.tip 2004-03-24 19:25:56 +0200
@@ -187,7 +187,7 @@
string is not the same length as the text it is replacing, the
string will be adjusted accordingly. \MODIFIES{}
\INDEXRAISES
- \begin{ruby}[comment*]
+ \begin{ruby}[comment*,synerr]
a = "hello"; a[2] = 96; a
a = "hello"; a[2, 4] = "xyz"; a
a = "hello"; a[-4, 2] = "xyz"; a
diff -urN ProgrammingRuby/latex/ref_c_struct__tms.tip ProgrammingRuby.build/latex/ref_c_struct__tms.tip
--- ProgrammingRuby/latex/ref_c_struct__tms.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/ref_c_struct__tms.tip 2004-03-24 19:25:56 +0200
@@ -3,7 +3,7 @@
% =====================================================
\begin{class}{Struct::Tms}{Struct}{}\label{ref:structtms}
- This structure is returned by \CCMI{Time.times}. It holds
+ This structure is returned by \CCMI{Process.times}. It holds
information on process times on those platforms that support it.
Not all values are valid on all platforms.%
\index{CPU times}%
@@ -23,11 +23,11 @@
\bottomrule
\end{tabularx}
- See also \C{Struct} \vpageref{ref:struct} and \CCMI{Time.times}
- \vpageref{ref:time:times}.
+ See also \C{Struct} \vpageref{ref:struct} and \CCMI{Process.times}
+ \vpageref{ref:process:times}.
\begin{ruby}[comment]
- t = Time.times
+ t = Process.times
[ t.utime, t.stime]
[ t.cutime, t.cstime ]
\end{ruby}
diff -urN ProgrammingRuby/latex/ref_c_thread.tip ProgrammingRuby.build/latex/ref_c_thread.tip
--- ProgrammingRuby/latex/ref_c_thread.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/ref_c_thread.tip 2004-03-24 20:11:26 +0200
@@ -122,8 +122,8 @@
\obj{block}, and begins running it. Any arguments passed to
\CCM{Thread.new} are passed into the block.
\begin{ruby}
- x = Thread.new { sleep .1; print "x"; print "y"; print "z" }
- a = Thread.new { print "a"; print "b"; sleep .2; print "c" }
+ x = Thread.new { sleep 0.1; print "x"; print "y"; print "z" }
+ a = Thread.new { print "a"; print "b"; sleep 0.2; print "c" }
x.join # Let the threads finish before
a.join # main thread exits...
!- print "\n"
diff -urN ProgrammingRuby/latex/ref_c_time.tip ProgrammingRuby.build/latex/ref_c_time.tip
--- ProgrammingRuby/latex/ref_c_time.tip 2001-01-23 23:59:42 +0200
+++ ProgrammingRuby.build/latex/ref_c_time.tip 2004-03-24 19:25:56 +0200
@@ -110,18 +110,6 @@
Synonym for \CCM{Time.new}.
\end{method}
- \begin{method}{times}{Time.times
- \returns{\obj{aStructTms}}}{A}
- Returns a \CF{Tms}\label{ref:time:times} structure (see \C{Struct::Tms}
- \vpageref{ref:structtms}) that contains
- user and system CPU times for this process.
-
- \begin{ruby}[comment]
- t = Time.times
- [ t.utime, t.stime ]
- \end{ruby}
- \end{method}
-
\begin{method}{utc}{\multiprot{%
Time.utc( \obj{year \opt{, month, day, hour, min, sec, usec}} )
\returns{\obj{aTime}} \\
diff -urN ProgrammingRuby/latex/ref_m_kernel.tip ProgrammingRuby.build/latex/ref_m_kernel.tip
--- ProgrammingRuby/latex/ref_m_kernel.tip 2001-02-10 18:19:17 +0200
+++ ProgrammingRuby.build/latex/ref_m_kernel.tip 2004-03-24 20:11:49 +0200
@@ -21,7 +21,7 @@
converted directly, \nil{} is converted to \CF{0.0}, and
the rest are converted using \emph{arg}.to\_f.
- \begin{ruby}[comment]
+ \begin{ruby}[comment,synerr]
Float(1)
Float(nil)
Float("123.456")
@@ -47,7 +47,7 @@
\METHOD{to\_s} method.
\begin{ruby}[comment]
String(self)
- String(self.type)
+ String(self.class)
String(123456)
\end{ruby}
\end{method}
@@ -360,10 +360,10 @@
\begin{ruby}
!- $stdout.sync = true
fork do
-!- 3.times {|i| puts "Child: #{i}\n"; sleep .05 }
+!- 3.times {|i| puts "Child: #{i}\n"; sleep 0.05 }
!+ 3.times {|i| puts "Child: #{i}" }
end
-!- 3.times {|i| puts "Parent: #{i}\n"; sleep .05 }
+!- 3.times {|i| puts "Parent: #{i}\n"; sleep 0.05 }
!+ 3.times {|i| puts "Parent: #{i}" }
Process.wait
\end{ruby} % $ <-- ispell kludge
@@ -838,7 +838,9 @@
\CF{*} & all & Use the next argument as the field width. If
negative, left-justify the result. If the asterisk is
followed by a number and a dollar sign, use
- the indicated argument as the width.\\
+ the indicated argument as the width. You cannot mix unnumbered
+ arguments with numbered ones, only one style should be used
+ in one format sequence.\\
\bottomrule
\end{tabularx}
\end{table}
@@ -880,8 +882,8 @@
\begin{ruby}[comment,showspace]
sprintf("%d %04x", 123, 123)
sprintf("%08b '%4s'", 123, 123)
- sprintf("%*2$s %d", "hello", 10)
- sprintf("%*2$s %d", "hello", -10)
+ sprintf("%*2$1$s %2$d", "hello", 10)
+ sprintf("%*2$1$s %2$d", "hello", -10)
sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23)
\end{ruby}
\end{method}
diff -urN ProgrammingRuby/latex/ref_m_process.tip ProgrammingRuby.build/latex/ref_m_process.tip
--- ProgrammingRuby/latex/ref_m_process.tip 2001-01-23 23:59:43 +0200
+++ ProgrammingRuby.build/latex/ref_m_process.tip 2004-03-24 19:30:29 +0200
@@ -92,7 +92,7 @@
process group, or user (an id of $0$ means \emph{current}).
Lower priorities are more favorable for
scheduling. Not available on all platforms.
- \begin{ruby}[comment]
+ \begin{ruby}[comment,norun]
Process.getpriority(Process::PRIO_USER, 0)
Process.getpriority(Process::PRIO_PROCESS, 0)
\end{ruby}
@@ -168,7 +168,7 @@
\returns{0}}{Varies}
See \MIM{Process.getpriority}.%
\index{Process!priority}
- \begin{ruby}[comment]
+ \begin{ruby}[comment,norun]
Process.setpriority(Process::PRIO_USER, 0, 19)
Process.setpriority(Process::PRIO_PROCESS, 0, 19)
Process.getpriority(Process::PRIO_USER, 0)
@@ -188,6 +188,18 @@
\end{ruby}
\end{method}
+ \begin{method}{times}{Process.times
+ \returns{\obj{aStructTms}}}{A}
+ Returns a \CF{Tms}\label{ref:process:times} structure (see \C{Struct::Tms}
+ \vpageref{ref:structtms}) that contains
+ user and system CPU times for this process.
+
+ \begin{ruby}[comment]
+ t = Process.times
+ [ t.utime, t.stime ]
+ \end{ruby}
+ \end{method}
+
\begin{method}{uid}{Process.uid
\returns{\obj{aFixnum}}}{A}
Returns the user id of this process.
diff -urN ProgrammingRuby/latex/rubybook.sty ProgrammingRuby.build/latex/rubybook.sty
--- ProgrammingRuby/latex/rubybook.sty 2001-01-23 23:59:43 +0200
+++ ProgrammingRuby.build/latex/rubybook.sty 2004-03-24 19:25:56 +0200
@@ -48,6 +48,7 @@
\usepackage{calc}
\usepackage{dcolumn}
\usepackage[dvips]{color}
+\usepackage[colorlinks=true,draft=false]{hyperref}
\usepackage{epsf}
\usepackage{fancybox}
\usepackage{fancyheadings}
@@ -67,7 +68,7 @@
\usepackage{pst-plot}
%\usepackage{setspace}
\usepackage{shadow}
-\usepackage[sf,compact,nops]{titlesec}
+\usepackage[sf,compact]{titlesec}
\usepackage{tabularx}
\usepackage{url}
\usepackage{varioref}
@@ -211,6 +212,7 @@
%%
%\def\SwallowComma#1,{\relax}
\def\SwallowComma{\relax}
+\let\seealso\undefined
\newcommand{\seealso}[2]{%
\index{\noexpand#1!ZZZZZ@\protect\SwallowComma|SeeAlso{#2}}%
}
diff -urN ProgrammingRuby/latex/temp.rb ProgrammingRuby.build/latex/temp.rb
--- ProgrammingRuby/latex/temp.rb 1970-01-01 03:00:00 +0300
+++ ProgrammingRuby.build/latex/temp.rb 2004-03-24 19:25:56 +0200
@@ -0,0 +1,3 @@
+module Temp
+def Temp.var() 4; end
+end
diff -urN ProgrammingRuby/latex/trouble.tip ProgrammingRuby.build/latex/trouble.tip
--- ProgrammingRuby/latex/trouble.tip 2001-01-23 23:59:43 +0200
+++ ProgrammingRuby.build/latex/trouble.tip 2004-03-24 19:25:56 +0200
@@ -280,7 +280,7 @@
indicates a missing \KW{end} keyword.
\item Make sure that the type of the object you are using is what you
- think it is. If in doubt, use \CIM{Object.type} to check the type
+ think it is. If in doubt, use \CIM{Object.class} to check the type
of an object.
\item Make sure that your methods start with a lowercase letter and
diff -urN ProgrammingRuby/latex/tut_classes.tip ProgrammingRuby.build/latex/tut_classes.tip
--- ProgrammingRuby/latex/tut_classes.tip 2001-01-23 23:59:43 +0200
+++ ProgrammingRuby.build/latex/tut_classes.tip 2004-03-24 19:25:56 +0200
@@ -930,7 +930,7 @@
\begin{ruby}[comment]
person = "Tim"
person.id
- person.type
+ person.class
person
\end{ruby}
@@ -938,7 +938,7 @@
value ``Tim.'' A reference to this object is placed in the local
variable \VAR{person}.
A quick check shows that the variable has indeed taken on the
-personality of a string, with an object id, a type, and a value.
+personality of a string, with an object id, a class type, and a value.
So, is a variable an object?
diff -urN ProgrammingRuby/latex/tut_containers.tip ProgrammingRuby.build/latex/tut_containers.tip
--- ProgrammingRuby/latex/tut_containers.tip 2001-03-12 05:47:49 +0200
+++ ProgrammingRuby.build/latex/tut_containers.tip 2004-03-24 19:25:56 +0200
@@ -41,7 +41,7 @@
\begin{ruby}[comment]
a = [ 3.14159, "pie", 99 ]
- a.type
+ a.class
a.length
a[0]
a[1]
@@ -49,7 +49,7 @@
a[3]
b = Array.new
- b.type
+ b.class
b.length
b[0] = "second"
b[1] = "array"
diff -urN ProgrammingRuby/latex/tut_expressions.tip ProgrammingRuby.build/latex/tut_expressions.tip
--- ProgrammingRuby/latex/tut_expressions.tip 2001-03-12 05:47:49 +0200
+++ ProgrammingRuby.build/latex/tut_expressions.tip 2004-03-24 20:02:53 +0200
@@ -377,7 +377,7 @@
\begingroup\VerbatimFont
\begin{tabular}{@{}llll@{}}
\multicolumn{4}{@{}l@{}}{\CF{a = [1, 2, 3, 4]}}\\
-\begin{ruby}[rawop]
+\begin{ruby}[rawop,norun]
[
'b, c = a',
'b, *c = a',
@@ -411,7 +411,7 @@
\begin{codefragment}
\begingroup\VerbatimFont
\begin{tabular}{@{}lll@{\ }l@{\ }l@{\ }l@{}}
-\begin{ruby}[rawop]
+\begin{ruby}[rawop,norun]
[
'b, (c, d), e = 1,2,3,4',
'b, (c, d), e = [1,2,3,4]',
@@ -543,7 +543,7 @@
\CF{defined?} returns the string ``yield'' if a code block is
associated with the current context.\label{tut:defined}
-\begin{ruby}[comment*]
+\begin{ruby}[comment*,norun]
defined? 1
defined? dummy
defined? printf
@@ -694,9 +694,9 @@
!-aSong = ""
!-def aSong.duration() 1 end
unless aSong.duration > 180 then
- cost = .25
+ cost = 0.25
else
- cost = .35
+ cost = 0.35
end
\end{ruby}
@@ -709,7 +709,7 @@
\begin{ruby}
!-aSong = ""
!-def aSong.duration() 1 end
-cost = aSong.duration > 180 ? .35 : .25
+cost = aSong.duration > 180 ? 0.35 : 0.25
\end{ruby}
The conditional expression returns the value of either the expression
diff -urN ProgrammingRuby/latex/tut_io.tip ProgrammingRuby.build/latex/tut_io.tip
--- ProgrammingRuby/latex/tut_io.tip 2001-01-23 23:59:43 +0200
+++ ProgrammingRuby.build/latex/tut_io.tip 2004-03-24 19:25:56 +0200
@@ -243,7 +243,7 @@
about the ``oracle'' user on our local machine using the finger
protocol.
-\begin{ruby}
+\begin{ruby}[norun]
require 'socket'
client = TCPSocket.open('localhost', 'finger')
client.send("oracle\n", 0) # 0 means standard packet
@@ -260,7 +260,7 @@
\vpageref{lib:net:ftp}. For example, the following program lists the
images that are displayed on the Pragmatic Programmer home page.
-\begin{ruby}
+\begin{ruby}[norun]
require 'net/http'
h = Net::HTTP.new('www.pragmaticprogrammer.com', 80)
diff -urN ProgrammingRuby/latex/tut_methods.tip ProgrammingRuby.build/latex/tut_methods.tip
--- ProgrammingRuby/latex/tut_methods.tip 2001-01-23 23:59:43 +0200
+++ ProgrammingRuby.build/latex/tut_methods.tip 2004-03-24 19:25:56 +0200
@@ -189,8 +189,7 @@
\begin{ruby}[comment]
self.id
id
- self.type
- type
+ self.class
\end{ruby}
This defaulting mechanism is how Ruby implements private
diff -urN ProgrammingRuby/latex/tut_modules.tip ProgrammingRuby.build/latex/tut_modules.tip
--- ProgrammingRuby/latex/tut_modules.tip 2001-01-23 23:59:43 +0200
+++ ProgrammingRuby.build/latex/tut_modules.tip 2004-03-24 19:25:56 +0200
@@ -112,7 +112,7 @@
module Debug
!- include D
def whoAmI?
- "#{self.type.name} (\##{self.id}): #{self.to_s}"
+ "#{self.class.name} (\##{self.id}): #{self.to_s}"
end
end
class Phonograph
diff -urN ProgrammingRuby/latex/tut_stdtypes.tip ProgrammingRuby.build/latex/tut_stdtypes.tip
--- ProgrammingRuby/latex/tut_stdtypes.tip 2001-01-23 23:59:43 +0200
+++ ProgrammingRuby.build/latex/tut_stdtypes.tip 2004-03-24 19:25:56 +0200
@@ -31,7 +31,7 @@
\begin{ruby}
num = 8
7.times do
- print num.type, " ", num, "\n"
+ print num.class, " ", num, "\n"
num *= num
end
\end{ruby}
@@ -1178,7 +1178,7 @@
\begin{ruby}[comment]
re = /cat/
- re.type
+ re.class
\end{ruby}
The method \CIMI{Regexp.match} matches a regular expression
@@ -1192,7 +1192,7 @@
\begin{ruby}[comment]
re = /(\d+):(\d+)/ # match a time hh:mm
md = re.match("Time: 12:34am")
- md.type
+ md.class
md[0] # == $&
md[1] # == $1
md[2] # == $2
diff -urN ProgrammingRuby/latex/tut_threads.tip ProgrammingRuby.build/latex/tut_threads.tip
--- ProgrammingRuby/latex/tut_threads.tip 2001-03-12 05:47:49 +0200
+++ ProgrammingRuby.build/latex/tut_threads.tip 2004-03-24 20:03:26 +0200
@@ -247,7 +247,7 @@
program.
\begin{ruby}[comment]
- t = Thread.new { sleep .1; Thread.pass; Thread.stop; }
+ t = Thread.new { sleep 0.1; Thread.pass; Thread.stop; }
t.status
t.run #!sh!
t.status
@@ -466,7 +466,7 @@
understand.%
\index{Pig Latin}
-\begin{ruby}
+\begin{ruby}[norun]
pig = IO.popen("pig", "w+")
pig.puts "ice cream after they go to bed"
pig.close_write
diff -urN ProgrammingRuby/util/benchmark.rb ProgrammingRuby.build/util/benchmark.rb
--- ProgrammingRuby/util/benchmark.rb 2001-01-24 00:10:47 +0200
+++ ProgrammingRuby.build/util/benchmark.rb 2004-03-24 19:25:56 +0200
@@ -27,9 +27,9 @@
end
def measure(label = "")
- t0, r0 = Time.times, Time.now
+ t0, r0 = Process.times, Time.now
yield
- t1, r1 = Time.times, Time.now
+ t1, r1 = Process.times, Time.now
Benchmark::Tms.new(t1.utime - t0.utime,
t1.stime - t0.stime,
t1.cutime - t0.cutime,
diff -urN ProgrammingRuby/util/code.rb ProgrammingRuby.build/util/code.rb
--- ProgrammingRuby/util/code.rb 2001-03-12 05:47:50 +0200
+++ ProgrammingRuby.build/util/code.rb 2004-03-24 19:27:35 +0200
@@ -132,17 +132,17 @@
chomp
- break if /^\s*\\end{ruby}/
+ break if $_ =~ /^\s*\\end\{ruby\}/
prefix = override if override and !prefix
- if /^\s*\\begin{(.*?)}/
+ if $_ =~ /^\s*\\begin\{(.*?)\}/
override = "!" + ($1 == "hidden" ? "-" : "+")
- elsif /^\s*\\end{(hidden|latex)}/
+ elsif $_ =~ /^\s*\\end\{(hidden|latex)\}/
override = nil
else
if prefix
- $_[0,2] = "" if /^!(.)/
+ $_[0,2] = "" if $_ =~ /^!(.)/
chunk.push prefix + $_
else
chunk.push $_
@@ -569,7 +569,7 @@
lines = []
while $stdin.gets
chomp
- if /\\end{syntax}/
+ if $_ =~ /\\end\{syntax\}/
last = $_
break
end
@@ -607,10 +607,10 @@
end
while $stdin.gets
- if /^\s*\\begin{ruby}(?:\[(.*?)\])?/
+ if $_ =~ /^\s*\\begin\{ruby\}(?:\[(.*?)\])?/
$codeCount += 1
handleCodeBlock($1 || "")
- elsif /^\s*\\begin{syntax}/
+ elsif $_ =~ /^\s*\\begin\{syntax\}/
handleSyntax
else
diff -urN ProgrammingRuby/util/genLibIndex.rb ProgrammingRuby.build/util/genLibIndex.rb
--- ProgrammingRuby/util/genLibIndex.rb 2001-01-24 00:10:47 +0200
+++ ProgrammingRuby.build/util/genLibIndex.rb 2004-03-24 19:25:56 +0200
@@ -22,31 +22,33 @@
gsub /%.*/, ''
- /\\begin\{(class|module)\}\{(.*?)\}/ or raise "No class|module"
- type = $1
- name = $2
+ a=/\\begin\{(class|module)\}\{([^}]*?)\}/.match($_)
+ a or raise "No class|module"
+ restype = a[1]
+ resname = a[2]
result = ""
- if (/begin\{classmethods\}(.*)\\end\{classmethods\}/m)
+
+ if ($_ =~ /begin\{classmethods\}(.*)\\end\{classmethods\}/m)
result << extract($1, "class");
end
- if (/begin\{methods\}(.*)\\end\{methods\}/m)
+ if ($_ =~ /begin\{methods\}(.*)\\end\{methods\}/m)
result << extract($1, "instance");
end
- if (/begin\{privatemethods\}(.*)\\end\{privatemethods\}/m)
+ if ($_ =~ /begin\{privatemethods\}(.*)\\end\{privatemethods\}/m)
result << extract($1, "private");
end
if result.length > 0
- puts "\\begin\{ls#{type}\}\{#{name}\}"
+ puts "\\begin\{ls#{restype}\}\{#{resname}\}"
puts result
- puts "\\end\{ls#{type}\}"
+ puts "\\end\{ls#{restype}\}"
else
- puts "\\begin\{lsx#{type}\}\{#{name}\}"
- puts "\\end\{lsx#{type}\}"
+ puts "\\begin\{lsx#{restype}\}\{#{resname}\}"
+ puts "\\end\{lsx#{restype}\}"
end
end
diff -urN ProgrammingRuby/util/optparse/CVS/Entries ProgrammingRuby.build/util/optparse/CVS/Entries
--- ProgrammingRuby/util/optparse/CVS/Entries 2002-12-03 20:11:51 +0200
+++ ProgrammingRuby.build/util/optparse/CVS/Entries 1970-01-01 03:00:00 +0300
@@ -1,2 +0,0 @@
-/time.rb/1.1/Tue Jan 23 22:10:47 2001//
-D
diff -urN ProgrammingRuby/util/optparse/CVS/Repository ProgrammingRuby.build/util/optparse/CVS/Repository
--- ProgrammingRuby/util/optparse/CVS/Repository 2002-12-03 20:11:51 +0200
+++ ProgrammingRuby.build/util/optparse/CVS/Repository 1970-01-01 03:00:00 +0300
@@ -1 +0,0 @@
-ruby/ProgrammingRuby/util/optparse
diff -urN ProgrammingRuby/util/optparse/CVS/Root ProgrammingRuby.build/util/optparse/CVS/Root
--- ProgrammingRuby/util/optparse/CVS/Root 2002-12-03 20:11:51 +0200
+++ ProgrammingRuby.build/util/optparse/CVS/Root 1970-01-01 03:00:00 +0300
@@ -1 +0,0 @@
-:pserver:anonymous@rubygarden.com:/usr/local/repository
diff -urN ProgrammingRuby/util/optparse/time.rb ProgrammingRuby.build/util/optparse/time.rb
--- ProgrammingRuby/util/optparse/time.rb 2001-01-24 00:10:47 +0200
+++ ProgrammingRuby.build/util/optparse/time.rb 1970-01-01 03:00:00 +0300
@@ -1,10 +0,0 @@
-require 'optparse'
-require 'parsedate'
-
-OptionParser.accept(Time) do |s|
- begin
- Time::mktime(*ParseDate::parsedate(s)[0...6])
- rescue
- raise OptionParser::InvalidArgument, s
- end
-end
diff -urN ProgrammingRuby/util/optparse.rb ProgrammingRuby.build/util/optparse.rb
--- ProgrammingRuby/util/optparse.rb 2001-01-24 00:10:47 +0200
+++ ProgrammingRuby.build/util/optparse.rb 1970-01-01 03:00:00 +0300
@@ -1,1526 +0,0 @@
-# optparse library, not octopus.
-
-=begin
-= Summary
-Parser library for command line options.
-
-features:
-(1) short and crunchable switches and long(GNU-style) switches.
-(2) you can switch definition and handler in same place.
-(3) arguments to switches are converted automatically.
-(4) also provides option summary.
-(5) you can add options after initialization or on the fly.
-
-=end #'#"#`#
-# Not yet (;_;)
-=begin
-
-== Class tree
- * ((<OptionParser>)) front end
- * ((<OptionParser::Switch>)) each switches
- * ((<OptionParser::List>)) options list
- * ((<OptionParser::ParseError>)) errors on parsing
- * ((<OptionParser::AmbiguousOption>))
- * ((<OptionParser::NeedlessArgument>))
- * ((<OptionParser::MissingArgument>))
- * ((<OptionParser::InvalidOption>))
- * ((<OptionParser::InvalidArgument>))
- * ((<OptionParser::AmbiguousArgument>))
-
-=end #'#"#`#
-
-=begin
-= Classes & Modules
-=end #'#"#`#
-
-class OptionParser
- Copyright = %$Copyleft: (c) 1999-2000 Nakada.Nobuyoshi <nobu.nokada@softhome.net> $.freeze
- RCSID = %w$Id: optparse.rb,v 1.1 2001/01/23 22:10:47 dave Exp $[1..-1].each {|s| s.freeze}.freeze
- Version = RCSID[1].split('.').collect {|s| s.to_i}.freeze
-
- NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
- RequiredArgument = [REQUIRED_ARGUMENT = :REQUIRED, true].freeze
- OptionalArgument = [OPTIONAL_ARGUMENT = :OPTIONAL, false].freeze
-
-=begin private
-== ((:OptionParser::Completion:))
-Keyword completion module.
-=end #'#"#`#
- module Completion
-=begin private
---- OptionParser::Completion#complete(key[, pat])
- Searches ((|key|)), or ((|pat|)) with completion if not found.
- :Parameters:
- : ((|key|))
- keyword to search.
- : ((|pat|))
- completion pattern.
-=end #'#"#`#
- def complete(key, pat = Regexp.new('\A' + Regexp.quote(key).gsub(/\w+/, '\&\w*'), true))
- canon, sw, k, v = nil
- each do |k, *v|
- (k.respond_to?(:id2name) ? k.id2name : k) =~ pat or next
- v << k if v.empty?
- if !canon
- canon, sw = k, v
- else
- throw :ambiguous, key unless sw == v
- end
- end
- if canon
- return yield(key, *sw) if iterator?
- return key, *sw
- end
- end
-
-=begin private
---- OptionParser::Completion#convert(opt, *val)
- Extracts the first element from result of
- ((<OptionParser::Completion#complete>)).
-=end #'#"#`#
- def convert(opt, *val)
- val
- end
- end
-
-=begin private
-== ((:OptionParser::Filling:))
-Extends method (({fill})) like as (({Array})).
-=end #'#"#`#
- module Filling
- def fill(val, arg)
- arg.each {|arg| self[arg] = val}
- self
- end
- def self.extend_object(obj)
- obj.respond_to?(:fill) or super
- end
- def self.append_features(klass)
- klass.instance_methods.include?('fill') or super
- end
- end
-
-=begin private
-== ((:OptionParser::OptionMap:))
-Map from option/keyword string to object with completion.
-=== Superclass
-(({Hash}))
-=== Including modules
-((<OptionParser::Completion>)), ((<OptionParser::Filling>))
-=end #'#"#`#
- class OptionMap < Hash
- include Completion
- include Filling
- end
-
-
-=begin
-== ((:OptionParser::Switch:))
-Individual switch class.
-=end #'#"#`#
- class Switch
- attr_reader :pattern, :conv, :short, :long, :arg, :desc, :block
-
-=begin private
-=== Class methods
-=end
-=begin private
---- OptionParser::Switch.guess(arg)
- Guesses argument style from ((|arg|)).
- Returns corresponding ((<OptionParser::Switch>)) subclass.
-=end #'#"#`#
- def self.guess(arg)
- case arg
- when ""
- self
- when /\A=?\[/
- Switch::OptionalArgument
- else
- Switch::RequiredArgument
- end
- end
-
-=begin private
---- OptionParser::Switch.new
-=end #'#"#`#
- def initialize(pattern = nil, conv = nil,
- short = nil, long = nil, arg = nil,
- desc = ([] if short or long), block = Proc.new)
- @pattern, @conv, @short, @long, @arg, @desc, @block =
- pattern, conv, short, long, arg, desc, block
- end
-
-=begin
-=== Instance methods
-=end
-=begin private
---- OptionParser::Switch#parse_arg(arg) {non-serious error handler}
- Parses argument and returns rest of ((|arg|)), and matched portion
- to the argument pattern.
- :Parameters:
- : ((|arg|))
- option argument to be parsed.
- : (({block}))
- yields when the pattern doesn't match sub-string.
-=end #'#"#`#
- def parse_arg(arg)
- pattern or return nil, arg
- unless m = pattern.match(arg)
- yield(InvalidArgument, arg)
- return arg, nil
- end
- if String === m
- m = [s = m]
- else
- m = m.to_a
- s = m[0]
- return nil, *m unless String === s
- end
- raise InvalidArgument, arg unless arg.rindex(s, 0)
- return nil, *m if s.length == arg.length
- yield(InvalidArgument, arg) # didn't match whole arg
- return arg[s.length..-1], *m
- end
- private :parse_arg
-
-=begin
---- OptionParser::Switch#parse(arg, val) {semi-error handler}
- Parses argument, convert and returns ((|arg|)), ((|block|)) and
- result of conversion.
- : Arguments to ((|@conv|))
- substrings matched to ((|@pattern|)), ((|$&|)), ((|$1|)),
- ((|$2|)) and so on.
- :Parameters:
- : ((|arg|))
- argument string follows the switch.
- : ((|val|))
- following argument.
- : (({block}))
- (({yields})) at semi-error condition, instead of raises exception.
-=end #'#"#`#
- def parse(arg, *val)
- if block
- return arg, block, *OptionParser.yieldproc(*val, &conv)
- else
- return arg, nil
- end
- end
-
-=begin private
---- OptionParser::Switch#summarize(sdone, ldone, width, max, indent)
- Makes summary strings.
- :Parameters:
- : ((|sdone|))
- already summarized short style options keyed hash.
- : ((|ldone|))
- already summarized long style options keyed hash.
- : ((|width|))
- width of left side, option part. in other word, right side,
- description part strings start at ((|width|)) column.
- : ((|max|))
- maximum width of left side, options are filled within ((|max|)) columns.
- : ((|indent|))
- prefix string indents each summarized lines.
- : (({block}))
- to be passed each lines(without newline).
-=end #'#"#`#
- def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
- sopts, lopts, s = [], [], nil
- @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
- @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
- return if sopts.empty? and lopts.empty? # completely hidden
-
- left = [sopts.join(', ')]
- right = desc.dup
-
- while s = lopts.shift
- l = left[-1].length + s.length
- l += arg.length if left.size == 1 && arg
- l < max or left << ''
- left[-1] << if left[-1].empty? then ' ' * 4 else ', ' end << s
- end
-
- left[0] << arg if arg
- mlen = left.collect {|s| s.length}.max.to_i
- while mlen > width and l = left.shift
- mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen
- yield(indent + l)
- end
-
- while (l = left.shift; r = right.shift; l or r)
- l = l.to_s.ljust(width) + ' ' + r if r and !r.empty?
- yield(indent + l)
- end
- end
-
-=begin private
---- OptionParser::Switch#-@
- Instantiates negated boolean switch, which calls ((|@block|)) with
- inversed value.
-=end #'#"#`#
- def -@
- type.new(@pattern, @conv, @short, @long, @arg, @desc) do |val|
- @block.call !val
- end
- end
-
-=begin private
-== Switch classes
-=end #'#"#`#
-
-=begin private
-=== ((:OptionParser::Switch::NoArgument:))
-Switch that takes no arguments.
-==== Superclass
-((<OptionParser::Switch>))
-==== Instance methods
---- OptionParser::Switch::NoArgument#parse
- Raises an exception if any arguments given.
-=end #'#"#`#
- class NoArgument < self
- def parse(arg, argv, &error)
- yield(NeedlessArgument, arg) if arg
- super(arg)
- end
- end
-
-=begin private
-=== ((:OptionParser::Switch::RequiredArgument:))
-Switch that takes an argument.
-==== Superclass
-((<OptionParser::Switch>))
-==== Instance methods
---- OptionParser::Switch::RequiredArgument#parse
- Raises an exception if argument is not present.
-=end #'#"#`#
- class RequiredArgument < self
- def parse(arg, argv, &error)
- unless arg
- raise MissingArgument if argv.empty?
- arg = argv.shift
- end
- super(*parse_arg(arg, &error))
- end
- end
-
-=begin private
-=== ((:OptionParser::Switch::OptionalArgument:))
-Switch that can omit argument.
-==== Superclass
-((<OptionParser::Switch>))
-==== Instance methods
---- OptionParser::Switch::OptionalArgument#parse
- Parses argument if given, or uses default value.
-=end #'#"#`#
- class OptionalArgument < self
- def parse(arg, argv, &error)
- if arg
- super(*parse_arg(arg, &error))
- else
- super(arg)
- end
- end
- end
- end
-
-
-=begin
-== ((:OptionParser::List:))
-Simple option list providing mapping from short and/or long option
-string to ((<OptionParser::Switch>)), and mapping from acceptable
-argument to matching pattern and converter pair. Also provides
-summary feature.
-=end #'#"#`#
- class List
-=begin
-=== Class methods
-=end #'#"#`#
-=begin private
---- OptionParser::List.new
- Just initializes all instance variables.
-=end #'#"#`#
- def initialize
- @atype = {}
- @short = OptionMap.new
- @long = OptionMap.new
- @list = []
- end
-
-=begin
-=== Instance methods
-=end #'#"#`#
-=begin
---- OptionParser::List#atype
- Map from acceptable argument types to pattern and converter pairs.
---- OptionParser::List#short
- Map from short style option switches to actual switch objects.
---- OptionParser::List#long
- Map from long style option switches to actual switch objects.
---- OptionParser::List#list
- List of all switches and summary string.
-=end #'#"#`#
- attr_reader :atype, :short, :long, :list
-
-=begin private
---- OptionParser::List#accept(type[, pattern]) {...}
- see ((<OptionParser.accept>)).
---- OptionParser::List#reject(type)
- see ((<OptionParser.reject>)).
-=end #'#"#`#
- def accept(t, pat = nil, &block)
- if pat
- pat.respond_to?(:match) or raise TypeError, "has no `match'"
- else
- pat = t if t.respond_to?(:match)
- end
- if !block
- block = pat.method(:convert) if pat.respond_to?(:convert)
- end
- @atype[t] = [pat, block]
- end
-
- def reject(t)
- @atype.delete(t)
- end
-
-=begin private
---- OptionParser::List#update(sw, sopts, lopts, nlopts = nil)
- Adds ((|sw|)) according to ((|sopts|)), ((|lopts|)) and
- ((|nlopts|)).
- :Parameters:
- : ((|sw|))
- ((<OptionParser::Switch>)) instance to be added.
- : ((|sopts|))
- short style options list.
- : ((|lopts|))
- long style options list.
- : ((|nlopts|))
- negated long style options list.
-=end #'#"#`#
- def update(sw, sopts, lopts, nlopts = nil)
- o = nil
- @short.fill(sw, sopts) if sopts and !sopts.empty?
- @long.fill(sw, lopts) if lopts and !lopts.empty?
- @long.fill(-sw, nlopts) if nlopts and !nlopts.empty?
- used = @short.invert.update(@long.invert)
- @list.delete_if {|o| Switch === o and !used[o]}
- end
- private :update
-
-=begin
---- OptionParser::List#prepend(switch, short_opts, long_opts, nolong_opts)
- Inserts ((|switch|)) at head of the list, and associates short,
- long and negated long options.
---- OptionParser::List#append(switch, short_opts, long_opts, nolong_opts)
- Appends ((|switch|)) at tail of the list, and associates short,
- long and negated long options.
- :Parameters:
- : ((|switch|))
- ((<OptionParser::Switch>)) instance to be inserted.
- : ((|short_opts|))
- list of short style options.
- : ((|long_opts|))
- list of long style options.
- : ((|nolong_opts|))
- list of long style options with (({"no-"})) prefix.
-=end #'#"#`#
- def prepend(*args)
- update(*args)
- @list.unshift(args[0])
- end
-
- def append(*args)
- update(*args)
- @list.push(args[0])
- end
-
-=begin
---- OptionParser::List#search(id, key) [{block}]
- Searches ((|key|)) in ((|id|)) list.
- :Parameters:
- : ((|id|))
- searching list.
- : ((|k|))
- searching key.
- : (({Block}))
- yielded with the found value when succeeded.
-=end #'#"#`#
- def search(id, key)
- if list = __send__(id)
- val = list.fetch(key) {return nil}
- return val unless iterator?
- yield(val)
- end
- end
-
-=begin
---- OptionParser::List#complete(id, opt, *pat, &block)
- Searches list ((|id|)) for ((|opt|)) and ((|*pat|)).
- :Parameters:
- : ((|id|))
- searching list.
- : ((|opt|))
- searching key.
- : ((|*pat|))
- optional pattern for completion.
- : (({Block}))
- yielded with the found value when succeeded.
-=end #'#"#`#
- def complete(id, opt, *pat, &block)
- __send__(id).complete(opt, *pat, &block)
- end
-
-=begin
---- OptionParser::List#summarize(*args) {...}
- Making summary table, yields the (({block})) with each lines.
- Each elements of (({@list})) should be able to (({summarize})).
- :Parameters:
- : ((|args|))
- passed to elements#summarize through.
- : (({block}))
- to be passed each lines(without newline).
-=end #'#"#`#
- def summarize(*args, &block)
- list.each do |opt|
- if opt.respond_to?(:summarize) # perhaps OptionParser::Switch
- opt.summarize(*args, &block)
- elsif opt.empty?
- yield("")
- else
- opt.each(&block)
- end
- end
- end
- end
-
-
-=begin private
-== ((:OptionParser::CompletingHash:))
-(({Hash})) with completion search feature.
-=== Superclass
-(({Hash}))
-=== Including modules
-((<OptionParser::Completion>))
-=end #'#"#`#
- class CompletingHash < Hash
- include Completion
-
-=begin private
-=== Instance methods
---- OptionParser::CompletingHash#match(key)
- Completion for hash key.
-=end #'#"#`#
- def match(key)
- return key, *fetch(key) {
- raise AmbiguousArgument, catch(:ambiguous) {return complete(key)}
- }.to_a
- end
- end
-
-
-=begin
-== ((:OptionParser:))
-The front-end of (({OptionParser})).
-=end #'#"#`#
-
-=begin
-=== Constants
-=end #'#"#`#
-
-=begin
---- OptionParser::ArgumentStyle
- Enumeration of acceptable argument styles; possible values are:
- : OptionParser::NO_ARGUMENT
- the switch takes no arguments. ((({:NONE})))
- : OptionParser::REQUIRED_ARGUMENT
- the switch requires an argument. ((({:REQUIRED})))
- : OptionParser::OPTIONAL_ARGUMENT
- the switch requires an optional argument, that is, may take or
- not. ((({:OPTIONAL})))
-
- Use like (({--switch=argument}))(long style) or
- (({-Xargument}))(short style). For short style, only portion
- matched to ((<argument pattern>)) is dealed as argument.
-=end #'#"#`#
- ArgumentStyle = {}
- ArgumentStyle.extend(Filling)
- ArgumentStyle.fill(Switch::NoArgument, NoArgument)
- ArgumentStyle.fill(Switch::RequiredArgument, RequiredArgument)
- ArgumentStyle.fill(Switch::OptionalArgument, OptionalArgument)
- ArgumentStyle.freeze
-
-=begin private
---- OptionParser::DefaultList
- Switches common used such as '--', and also provides default
- argument classes
-=end #'#"#`#
- DefaultList = List.new
- DefaultList.short['-'] = Switch::NoArgument.new {}
- DefaultList.long[''] = Switch::NoArgument.new {throw :terminate}
-
-=begin undocumented
-=== Default options
-Default options, which never appear in option summary.
---- --help
- Shows option summary.
---- --version
- Shows version string if (({::Version})) is defined.
-=end #'#"#`#
- DefaultList.long['help'] = Switch::NoArgument.new do
- puts ARGV.options
- exit
- end
- DefaultList.long['version'] = Switch::NoArgument.new do
- if defined?(::Version)
- puts "version #{::Version.join('.')}"
- exit
- end
- end
-
-=begin
-=== Class methods
-=end #'#"#`#
-
-=begin
---- OptionParser.with([banner[, width[, indent]]]) [{...}]
- Initializes new instance, and evaluates the block in context of
- the instance if called as iterator. This behavior is equivalent
- to older (({new})). This is ((*deprecated*)) method.
-
- cf. ((<OptionParser.new>))
- :Parameters:
- : ((|banner|))
- banner message.
- : ((|width|))
- summary width.
- : ((|indent|))
- summary indent.
- : (({Block}))
- to be evaluated in the new instance context.
-=end #'#"#`#
- def self.with(*args, &block)
- opts = new(*args)
- opts.instance_eval(&block)
- opts
- end
-
-=begin
---- OptionParser.new([banner[, width[, indent]]]) [{...}]
- Initializes the instance, and yields itself if called as iterator.
- :Parameters:
- : ((|banner|))
- banner message.
- : ((|width|))
- summary width.
- : ((|indent|))
- summary indent.
- : (({Block}))
- to be evaluated in the new instance context.
-=end #'#"#`#
- def initialize(banner = nil, width = 32, indent = ' ' * 4)
- @stack = [DefaultList, List.new, List.new]
- @program_name = nil
- @banner = banner
- @summary_width = width
- @summary_indent = indent
- yield self if iterator?
- end
-
-=begin
---- OptionParser.terminate([arg])
- Terminates option parsing. Optional parameter ((|arg|)) would be
- pushed back if given.
- :Parameters:
- : ((|arg|))
- string pushed back to be first non-option argument
-=end #'#"#`#
- def terminate(arg = nil)
- type.terminate(arg)
- end
- def self.terminate(arg = nil)
- throw :terminate, arg
- end
-
- @stack = [DefaultList]
- def self.top() DefaultList end
-
-=begin
---- OptionParser.accept(t, [pat]) {...}
---- OptionParser#accept(t, [pat]) {...}
- Directs to accept specified class argument.
- :Parameters:
- : ((|t|))
- argument class specifier, any object including Class.
- : ((|pat|))
- pattern for argument, defaulted to ((|t|)) if it respond to (({match})).
- : (({Block}))
- receives argument string and should be convert to desired class.
-=end #'#"#`#
- def accept(*args, &blk) top.accept(*args, &blk) end
- def self.accept(*args, &blk) top.accept(*args, &blk) end
-
-=begin
---- OptionParser.reject(t)
---- OptionParser#reject(t)
- Directs to reject specified class argument.
- :Parameters:
- : ((|t|))
- argument class specifier, any object including Class.
-=end #'#"#`#
- def reject(*args, &blk) top.reject(*args, &blk) end
- def self.reject(*args, &blk) top.reject(*args, &blk) end
-
-=begin private
---- OptionParser.yieldproc(*args) {block}
- Yields (({Proc})) or (({Method})) as iterator block with arguments
- ((|args|)).
- :Parameters:
- : ((|*args|))
- arguments to (({Block}))
- : (({Block}))
- (({Proc})) or (({Method})) to call. Must be passed as block.
-=end #'#"#`#
- def self.yieldproc(*args)
- iterator? or return *args
- if args.empty?
- return *yield
- else
- return *yield(*args)
- end
- end
-
-
-=begin
-=== Instance methods
-=end #'#"#`#
-
-=begin
---- OptionParser#banner
---- OptionParser#banner=(heading)
- Heading banner preceding summary.
---- OptionParser#summary_width
---- OptionParser#summary_width=(width)
- Width for option list portion of summary. Must be (({Numeric})).
---- OptionParser#summary_indent
---- OptionParser#summary_indent=(indent)
- Indentation for summary. Must be (({String})) (or have (({+ String}))).
---- OptionParser#program_name
---- OptionParser#program_name=(name)
- Program name to be emitted in error message and default banner,
- defaulted to (({$0})).
-=end #'#"#`#
- attr_writer :banner, :program_name
- attr_accessor :summary_width, :summary_indent
-
- def banner
- @banner ||= "Usage: #{program_name} [options]\n"
- end
-
- def program_name
- @program_name || $0
- end
-
-# for experimental cascading :-)
- alias set_banner banner=
- alias set_program_name program_name=
- alias set_summary_width summary_width=
- alias set_summary_indent summary_indent=
-
-=begin
---- OptionParser#top
- Subject of ((<on>))/((<on_head>)), ((<accept>))/((<reject>)).
-=end #'#"#`#
- def top
- @stack[-1]
- end
-
-=begin
---- OptionParser#base
- Subject of ((<on_tail>)).
-=end #'#"#`#
- def base
- @stack[1]
- end
-
-=begin
---- OptionParser#new
- Pushes a new (({List})).
-=end #'#"#`#
- def new
- @stack.push(List.new)
- if iterator?
- yield self
- else
- self
- end
- end
-
-=begin
---- OptionParser#remove
- Removes the last (({List})).
-=end #'#"#`#
- def remove
- @stack.pop
- end
-
-
-=begin
---- OptionParser#summarize(to = [], width = @summary_width, max = width - 1, indent = @summary_indent)
- Puts option summary into ((|to|)), and returns ((|to|)).
- :Parameters:
- : ((|to|))
- output destination, which must have method ((|<<|)). Defaulted to (({[]})).
- : ((|width|))
- width of left side. Defaulted to ((|@summary_width|))
- : ((|max|))
- maximum length allowed for left side. Defaulted to (({((|width|)) - 1}))
- : ((|indent|))
- indentation. Defaulted to ((|@summary_indent|))
- : (({Block}))
- yields with each line if called as iterator.
-=end #'#"#`#
- def summarize(to = [], width = @summary_width, max = width - 1, indent = @summary_indent, &blk)
- visit(:summarize, {}, {}, width, max, indent, &(blk || proc {|l| to << l + $/}))
- to
- end
-
-=begin
---- OptionParser#to_str
---- OptionParser#to_s
- Returns option summary string.
-=end #'#"#`#
- def to_str; summarize(banner.to_s.dup) end
- alias to_s to_str
-
-=begin
---- OptionParser#to_a
- Returns option summary list.
-=end #'#"#`#
- def to_a; summarize(banner.to_a.dup) end
-
-
-=begin
---- OptionParser#switch
- Creates ((<OptionParser::Switch>)).
- :Parameters:
- : ((|*opts|))
- option definition:
- : argument style
- see ((<OptionParser::ArgumentStyle>))
- : argument pattern
- acceptable option argument format, must pre-defined with
- ((<OptionParser.accept>)) or ((<OptionParser#accept>)), or
- (({Regexp})). This can appear once or assigned as (({String}))
- if not present, otherwise causes exception (({ArgumentError})).
-
- cf. ((<Acceptable argument classes>)).
- : Hash
- : Array
- possible argument values.
- : Proc
- : Method
- alternative way to give the ((*handler*)).
- : "--switch=MANDATORY", "--switch[=OPTIONAL]", "--switch"
- specifies long style switch that takes ((*mandatory*)),
- ((*optional*)) and ((*no*)) argument, respectively.
- : "-xMANDATORY", "-x[OPTIONAL]", "-x"
- specifies short style switch that takes ((*mandatory*)),
- ((*optional*)) and ((*no*)) argument, respectively.
- : "-[a-z]MANDATORY", "-[a-z][OPTIONAL]", "-[a-z]"
- special form short style switch that matches character
- range(not fullset of regular expression).
- : "=MANDATORY", "=[OPTIONAL]"
- argument style and description.
- : "description", ...
- ((*description*)) for this option.
- : (({Block}))
- ((*handler*)) to convert option argument to arbitrary (({Class})).
-=end #'#"#`#
- def switch(*opts, &block)
- short, long, nolong, style, pattern, conv = [], [], []
- ldesc, sdesc, desc, arg = [], [], []
- default_style = Switch::NoArgument
- default_pattern = nil
- klass = nil
- o = nil
- k = nil
-
- # local method: checks never given twice an argument.
- notwice = proc do |t, o, m|
- unless !o or o == t
- begin
- raise ArgumentError, "argument #{m} given twice"
- rescue
- $@[0, 2] = nil
- raise
- end
- end
- t
- end
-
- opts.each do |o|
- # argument class
- next if search(:atype, o) do |default_pattern, conv|
- klass = notwice[o, klass, 'type']
- end
- Module === o and
- raise ArgumentError, "unsupported argument type: #{o}"
-
- # directly specified pattern(any object possible to match)
- if o.respond_to?(:match)
- pattern = notwice[o, pattern, 'pattern']
- conv = (pattern.method(:convert) if pattern.respond_to?(:convert))
- next
- end
-
- # anything others
- case o
- when Proc, Method
- block = notwice[o, block, 'block']
- when Array, Hash
- case pattern
- when CompletingHash
- when nil
- pattern = CompletingHash.new
- conv = (pattern.method(:convert) if pattern.respond_to?(:convert))
- else
- raise ArgumentError, "argument pattern given twice"
- end
- if Array === o
- o.each {|o| pattern[(Array === o ? o.shift : o)] = o}
- else
- pattern.update(o)
- end
- when *ArgumentStyle.keys
- style = notwice[ArgumentStyle[o], style, 'style']
- when /^--no-([^][=]*)(.+)?/
- o = notwice[FalseClass, klass, 'type']
- default_style = default_style.guess(arg = $2) if $2
- default_pattern, conv = search(:atype, o)
- ldesc << "--no-#{$1}"
- long << 'no-' + (o = $1.downcase)
- nolong << o
- when /^--(\[no-\])?([^][=]*)(.+)?/
- o = notwice[$3 && !$1 ? Object : TrueClass, klass, 'type']
- default_style = default_style.guess(arg = $3) if $3
- default_pattern, conv = search(:atype, o)
- ldesc << "--#{$1}#{$2}"
- long << (o = $2.downcase)
- nolong << 'no-' + o if $1
- when /^-(\[\^?\]?(?:[^\\\]]|\\.)*\])(.+)?/
- o = notwice[Object, klass, 'type']
- default_style = default_style.guess(arg = $2) if $2
- default_pattern, conv = search(:atype, o)
- sdesc << "-#{$1}"
- short << Regexp.new($1)
- when /^-(.)(.+)?/
- o = notwice[($2 ? Object : TrueClass), klass, 'type']
- default_style = default_style.guess(arg = $2) if $2
- default_pattern, conv = search(:atype, o)
- sdesc << "-#{$1}"
- short << $1
- when /^=/
- style = notwice[default_style.guess(arg = o), style, 'style']
- default_pattern, conv = search(:atype, Object)
- else
- desc.push(o)
- end
- end
-
- s = if short.empty? and long.empty?
- raise ArgumentError, "no switch given" if style or pattern or block
- desc
- else
- (style || default_style).new(pattern || default_pattern,
- conv, sdesc, ldesc, arg, desc, block)
- end
- return s, short, long, nolong
- end
-
-=begin
---- OptionParser#on(*opts) [{...}]
---- OptionParser#on_head(*opts) [{...}]
---- OptionParser#on_tail(*opts) [{...}]
- Defines option switch and handler. (({on_head})) and (({on_tail})) put
- the switch at head and tail of summary, respectively.
-
- cf. ((<OptionParser#switch>)).
-=end #'#"#`#
- def on(*opts, &block)
- top.append(*switch(*opts, &block))
- self
- end
-
- def on_head(*opts, &block)
- top.prepend(*switch(*opts, &block))
- self
- end
-
- def on_tail(*opts, &block)
- base.append(*switch(*opts, &block))
- self
- end
-
-
-=begin
---- OptionParser#order(*argv) [{...}]
---- OptionParser#order!([argv = ARGV]) [{...}]
- Parses ((|argv|)) in order. When non-option argument encountered,
- yields it if called as iterator, otherwise terminates the parse
- process.
- Returns rest of ((|argv|)) left unparsed.
-
- (({order!})) takes argument array itself, and removes switches
- destructively.
- Defaults to parse ((|ARGV|)).
- :Parameters:
- : ((|argv|))
- command line arguments to be parsed.
- : (({Block}))
- called with each non-option argument.
-=end #'#"#`#
- def order(*argv, &block) order!(argv, &block) end
-
- def order!(argv = ARGV, &nonopt)
- opt, arg, sw, val = nil
- nonopt ||= proc {|arg| throw :terminate, arg}
- argv.unshift(arg) if arg = catch(:terminate) do
- while arg = argv.shift
- case arg
- # long option
- when /\A--([^=]*)(?:=(.*))?/
- begin
- sw, = complete(:long, opt = $1)
- rescue ParseError
- raise $!.set_option(arg, true)
- end
- begin
- opt, sw, *val = sw.parse($2, argv) {|*exc| raise *exc}
- OptionParser.yieldproc(*val, &sw)
- rescue ParseError
- raise $!.set_option(arg, $2)
- end
-
- # short option
- when /\A-(.)((=)(.*)|.+)?/
- opt, has_arg, eq, val = $1, $3, $3, $4 || $2
- begin
- unless sw = search(:short, opt)
- begin
- sw, = complete(:short, opt, opt)
- # short option matched.
- val = arg.sub(/\A-/, '')
- rescue InvalidOption
- # if no short options match, try completion with long
- # options.
- sw, = complete(:long, opt)
- eq ||= !$2
- end
- end
- rescue ParseError
- raise $!.set_option(arg, true)
- end
- begin
- opt, sw, *val = sw.parse(val, argv) {|*exc| raise *exc if eq}
- argv.unshift(opt) if opt and (opt = opt.sub(/\A-*/, '-')) != '-'
- OptionParser.yieldproc(*val, &sw)
- rescue ParseError
- raise $!.set_option(arg, has_arg)
- end
-
- # non-option argument
- else
- nonopt.call(arg)
- end
- end
- end
-
- argv
- end
-
-=begin
---- OptionParser#permute(*argv)
---- OptionParser#permute!([argv = ARGV])
- Parses ((|argv|)) in permutation mode, and returns list of
- non-option arguments.
-
- (({permute!})) takes argument array itself, and removes switches
- destructively.
- Defaults to parse ((|ARGV|)).
- :Parameters:
- : ((|argv|))
- command line arguments to be parsed.
-=end #'#"#`#
- def permute(*argv)
- permute!(argv)
- end
-
- def permute!(argv = ARGV)
- nonopts = []
- arg = nil
- order!(argv) {|arg| nonopts << arg}
- argv[0, 0] = nonopts
- argv
- end
-
-=begin
---- OptionParser#parse(*argv)
---- OptionParser#parse!([argv = ARGV])
- Parses ((|argv|)) in order when environment variable (({POSIXLY_CORRECT}))
- is set, otherwise permutation mode
-
- (({parse!})) takes argument array itself, and removes switches
- destructively.
- Defaults to parse ((|ARGV|)).
- :Parameters:
- : ((|argv|))
- command line arguments to be parsed.
-=end #'#"#`#
- def parse(*argv)
- parse!(argv)
- end
-
- def parse!(argv = ARGV)
- if ENV.include?('POSIXLY_CORRECT')
- order!(argv)
- else
- permute!(argv)
- end
- end
-
-
-=begin private
---- OptionParser#visit(id, *args) {block}
- Traverses (({stack}))s calling method ((|id|)) with ((|*args|)).
- :Parameters:
- : ((|id|))
- called method in each elements of (({stack}))s.
- : ((|*args|))
- passed to ((|id|)).
- : (({Block}))
- passed to ((|id|)).
-=end #'#"#`#
- def visit(id, *args, &block)
- el = nil
- @stack.reverse_each do |el|
- el.send(id, *args, &block)
- end
- nil
- end
- private :visit
-
-=begin private
---- OptionParser#search(id, k)
- Searches ((|k|)) in stack for ((|id|)) hash, and returns it or yielded
- value if called as iterator.
- :Parameters:
- : ((|id|))
- searching table.
- : ((|k|))
- searching key.
- : (({Block}))
- yielded with the found value when succeeded.
-=end #'#"#`#
- def search(id, k)
- k = catch(:found) do
- visit(:search, id, k) {|k| throw :found, k}
- return
- end
- return k unless iterator?
- yield(k)
- end
- private :search
-
-=begin private
---- OptionParser#complete(typ, opt, *etc)
- Completes shortened long style option switch, and returns pair of
- canonical switch and switch descriptor((<OptionParser::Switch>)).
- :Parameters:
- : ((|id|))
- searching table.
- : ((|opt|))
- searching key.
- : ((|*pat|))
- optional pattern for completion.
- : (({Block}))
- yielded with the found value when succeeded.
-=end #'#"#`#
- def complete(typ, opt, *pat)
- catch(:found) {
- if pat.empty?
- search(typ, opt) {|sw| throw :found, [sw, opt]} # exact match or...
- end
- raise AmbiguousOption, catch(:ambiguous) {
- visit(:complete, typ, opt, *pat) {|opt, *sw| throw :found, sw}
- raise InvalidOption, opt
- }
- }
- end
- private :complete
-
-=begin undocumented
---- OptionParser::load([filename])
- Loads options from file named as ((|filename|)). Does nothing when
- the file is not present.
- :Parameters:
- : ((|filename|))
- option file name. defaulted to basename of the program without
- suffix in a directory ((%~/.options%)).
-=end #'#"#`#
- def load(filename = File.expand_path(File.basename($0, '.*'), '~/.options'))
- begin
- parse(*IO.readlines(filename).each {|s| s.chomp!})
- rescue Errno::ENOENT, Errno::ENOTDIR
- # ignore silently unless exist
- end
- end
-
-=begin undocumented
---- OptionParser::environment([env])
- Parses environment variable ((|env|)) or its uppercase with spliting
- like as shell.
- :Parameters:
- : ((|env|))
- defaulted to basename of the program.
-=end #'#"#`#
- def environment(env = File.basename($0, '.*'))
- env = ENV[env] || ENV[env.upcase] or return
- parse(*Shellwords.shellwords(env))
- end
-
-
-=begin
-= Acceptable argument classes
-=end #'#"#`#
-
-=begin
-: Object
- any string, and no conversion. this is fall-back.
-=end #'#"#`#
- accept(Object)
-
-=begin
-: String
- any none-empty string, and no conversion.
-=end #'#"#`#
- accept(String, /.+/)
-
-=begin
-: Integer
- Ruby/C-like integer, octal for (({0-7})) sequence, binary for
- (({0b})), hexadecimal for (({0x})), and decimal for others; with
- optional sign prefix. Converts to (({Integer})).
-=end #'#"#`#
- accept(Integer, /\A[-+]?(?:0([0-7]+|b[01]+|x[\da-f]+)|\d+)/i) {|s, o|
- if o
- s.oct
- elsif s
- s.to_i
- end
- }
-
-=begin
-: Float
- Float number format, and converts to (({Float})).
-=end #'#"#`#
- accept(Float, /\A[-+]?(?:\d+\.\d*|\.?\d+)(?:E[-+]?\d+)?/i) {|s| s ? s.to_f : 0.0}
-
-=begin
-: Numeric
- Generic numeric format, and converts to (({Integer})) for integer
- format, (({Float})) for float format.
-=end #'#"#`#
- accept(Numeric,
- /\A[-+]?(?:(\d+\.\d*|\d*\.\d+)(?:E[-+]?\d+)?|0([0-7]+|b[01]+|x[\da-f]+))|\d+(E[-+]?\d+)?/i) {
- |s, f, o, e|
- if f or e
- s.to_f
- elsif o
- s.oct
- elsif s
- s.to_i
- end
- }
-
-=begin
-: OptionParser::DecimalInteger
- Decimal integer format, to be converted to (({Integer})).
-=end #'#"#`#
- DecimalInteger = /\A[-+]?\d+/
- accept(DecimalInteger) {|s| s.to_i if s}
-
-=begin
-: OptionParser::OctalInteger
- Ruby/C like octal/hexadecimal/binary integer format, to be converted
- to (({Integer})).
-=end #'#"#`#
- OctalInteger = /\A[-+]?(?:0b[01]+|0x[\da-f]+|[0-7]+)/i
- accept(OctalInteger) {|s| s.oct if s}
-
-=begin
-: OptionParser::DecimalNumeric
- Decimal integer/float number format, to be converted to
- (({Integer})) for integer format, (({Float})) for float format.
-=end #'#"#`#
- DecimalNumeric = /\A[-+]?(?:(\d+\.\d*|\d*\.\d+)(?:E[-+]?\d+)?)|\d+(E[-+]?\d+)?/i
- #/\A[-+]?(?:\d+|\d*\.\d+)(?:E[-+]?\d+)?/i
- accept(DecimalNumeric) {|s, f, e|
- if f or e
- s.to_f
- elsif s
- s.to_i
- end
- }
-
-=begin
-: TrueClass
- Boolean switch, which means whether it is present or not, whether it
- is absent or not with prefix (({no-})), or it takes an argument
- (({yes/no/true/false/+/-})).
-: FalseClass
- Similar to ((<TrueClass>)), but defaulted to (({false})).
-=end #'#"#`#
- yesno = CompletingHash.new.extend(Filling)
- yesno.fill(false, %w[- no false])
- yesno.fill(true, %w[+ yes true])
- yesno['nil'] = false # shoud be nil?
- accept(TrueClass, yesno) {|arg, val| val == nil or val}
- accept(FalseClass, yesno) {|arg, val| val != nil and val}
-
-=begin
-: Array
- List of strings separated by ","
-=end #'#"#`#
- accept(Array) {|s| s.split(',') if s}
-
-
-=begin
-= Exceptions
-=end #'#"#`#
-
-=begin
-== ((:OptionParser::ParseError:))
-Base class of exceptions from ((<OptionParser>))
-=== Superclass
-(({RuntimeError}))
-=== Constants
-: OptionParser::ParseError::Reason
- Reason caused error.
-=== Instance methods
---- OptionParser::ParseError#recover(argv)
- Push backs erred argument(s) to ((|argv|)).
---- OptionParser::ParseError#reason
- Returns error reason. Override this to I18N.
---- OptionParser::ParseError#inspect
- Returns inspection string.
---- OptionParser::ParseError#message
---- OptionParser::ParseError#to_s
---- OptionParser::ParseError#to_str
- Default stringizing method to emit standard error message.
-=end #'#"#`#
- class ParseError < RuntimeError
- Reason = 'parse error'.freeze
-
- def initialize(*args)
- @args = args
- end
-
- attr_reader :args
-
- def recover(argv)
- argv[0, 0] = @args
- argv
- end
-
- def set_option(opt, eq)
- if eq
- @args[0] = opt
- else
- @args.unshift(opt)
- end
- self
- end
-
- def reason
- self.type::Reason
- end
-
- def inspect
- '#<' + type.to_s + ': ' + args.join(' ') + '>'
- end
-
- def message
- reason + ': ' + args.join(' ')
- end
-
- alias to_s message
- alias to_str message
- end
-
-=begin
-== ((:OptionParser::AmbiguousOption:))
-Raises when encountered ambiguously completable string.
-=== Superclass
-((<OptionParser::ParseError>))
-=end #'#"#`#
- class AmbiguousOption < ParseError
- Reason = 'ambiguous option'.freeze
- end
-
-=begin
-== ((:OptionParser::NeedlessArgument:))
-Raises when encountered argument for switch defined as which takes no
-argument.
-=== Superclass
-((<OptionParser::ParseError>))
-=end #'#"#`#
- class NeedlessArgument < ParseError
- Reason = 'needles argument'.freeze
- end
-
-=begin
-== ((:OptionParser::MissingArgument:))
-Raises when no argument found for switch defined as which needs
-argument.
-=== Superclass
-((<OptionParser::ParseError>))
-=end #'#"#`#
- class MissingArgument < ParseError
- Reason = 'missing argument'.freeze
- end
-
-=begin
-== ((:OptionParser::InvalidOption:))
-Raises when undefined switch.
-=== Superclass
-((<OptionParser::ParseError>))
-=end #'#"#`#
- class InvalidOption < ParseError
- Reason = 'invalid option'.freeze
- end
-
-=begin
-== ((:OptionParser::InvalidArgument:))
-Raises when the given argument does not match required format.
-=== Superclass
-((<OptionParser::ParseError>))
-=end #'#"#`#
- class InvalidArgument < ParseError
- Reason = 'invalid argument'.freeze
- end
-
-=begin
-== ((:OptionParser::AmbiguousArgument:))
-Raises when the given argument word can't completed uniquely.
-=== Superclass
-((<OptionParser::InvalidArgument>))
-=end #'#"#`#
- class AmbiguousArgument < InvalidArgument
- Reason = 'ambiguous argument'.freeze
- end
-
-
-=begin
-= Miscellaneous
-=end #'#"#`#
-=begin
-== ((:OptionParser::Arguable:))
-Extends command line arguments array to parse itself.
-=end #'#"#`#
- module Arguable
-=begin
---- OptionParser::Arguable#options=(opt)
- Sets ((<OptionParser>)) object, when ((|opt|)) is (({false})) or
- (({nil})), methods ((<OptionParser::Arguable#options>)) and
- ((<OptionParser::Arguable#options=>)) are undefined. Thus, there
- is no ways to access the ((<OptionParser>)) object via the
- receiver object.
-=end #'#"#`#
- def options=(opt)
- unless @optparse = opt
- class << self
- undef_method(:options)
- undef_method(:options=)
- end
- end
- end
-
-=begin
---- OptionParser::Arguable#options
- Actual ((<OptionParser>)) object, automatically created if not
- yet.
-
- If called as iterator, yields with the ((<OptionParser>)) object
- and returns the result of the block. In this case, rescues any
- ((<OptionParser::ParseError>)) exceptions in the block, just emits
- error message to ((<STDERR>)) and returns (({nil})).
-
- :Parameters:
- : (({block}))
- Yielded with the ((<OptionParser>)) instance.
-
-=end #'#"#`#
- def options
- @optparse ||= OptionParser.new
- if iterator?
- begin
- yield @optparse
- rescue ParseError
- STDERR.puts @optparse.program_name + ': ' + $!
- nil
- end
- else
- @optparse
- end
- end
-
-=begin
---- OptionParser::Arguable#order!
---- OptionParser::Arguable#permute!
---- OptionParser::Arguable#parse!
- Parses ((|self|)) destructively, and returns ((|self|)) just contains
- rest arguments left without parsed.
-=end #'#"#`#
- def order!(&blk) options.order!(self, &blk) end
- def permute!() options.permute!(self) end
- def parse!() options.parse!(self) end
-
-=begin private
-Initializes instance variable.
-=end #'#"#`#
- def self.extend_object(obj)
- super
- obj.instance_eval {@optparse = nil}
- end
- def initialize(*args)
- super
- @optparse = nil
- end
- end
-
-=begin
-== OptionParser::Acceptables
-Acceptable argument classes. Now contains (({DecimalInteger})),
-(({OctalInteger})) and (({DecimalNumeric})).
-see ((<Acceptable argument classes>)).
-=end #'#"#`#
- module Acceptables
- DecimalInteger = OptionParser::DecimalInteger
- OctalInteger = OptionParser::OctalInteger
- DecimalNumeric = OptionParser::DecimalNumeric
- end
-end
-
-# ARGV is arguable by OptionParser
-ARGV.extend(OptionParser::Arguable)
-
-
-if $0 == __FILE__
- Version = OptionParser::Version
- ARGV.parse!.empty? or puts "what's #{ARGV.join(' ')}?"
-end
-__END__
-=begin example
-= Example
-<<< opttest.rb
-=end #'#"#`#
diff -urN ProgrammingRuby/util/racc/parser.rb ProgrammingRuby.build/util/racc/parser.rb
--- ProgrammingRuby/util/racc/parser.rb 2001-01-24 00:10:48 +0200
+++ ProgrammingRuby.build/util/racc/parser.rb 1970-01-01 03:00:00 +0300
@@ -1,384 +0,0 @@
-#
-# parser.rb
-#
-# Copyright (c) 1999 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
-#
-# This program is free software.
-# You can distribute/modify this program under the terms of
-# the GNU Lesser General Public License version 2 or later.
-#
-# As a special exception, when this code is copied by Racc
-# into a Racc output file, you may use that output file
-# without restriction.
-#
-
-unless defined? ParseError then
- class ParseError < StandardError; end
-end
-
-
-module Racc
-
-
-class Parser
-
- private
-
-
- begin
- require 'racc/cparse' # def _c_parse
- Racc_Main_Parsing_Routine = :_c_parse
- rescue LoadError
- Racc_Main_Parsing_Routine = :_rb_parse
- end
-
-
- def next_token
- raise NotImplementError, "#{self.type}#next_token must be defined"
- end
-
-
- def do_parse
- t = self.type
- unless t::Racc_debug_parser then
- @yydebug = false
- end
- @yydebug = @yydebug ? true : false
- if @yydebug then
- @racc_debug_out ||= $stderr
- end
-
- send Racc_Main_Parsing_Routine, t::Racc_arg, false
- end
-
-
- def _rb_parse( arg, in_debug )
- action_table, action_check, action_default, action_pointer,
- goto_table, goto_check, goto_default, goto_pointer,
- nt_base, reduce_table, token_table, shift_n, reduce_n = *arg
-
- #
- # local variables
- #
-
- state = [ 0 ]
- curstate = 0
-
- tstack = []
- vstack = []
-
- atmp = tok = val = t = nil
- act = tmp = code = i = nil
- read_next = true
-
- @racc_error_status = 0
- nerr = 0
- user_yyerror = false
-
- t_end = 0 # $end
- t_err = 1 # error token
-
- yydebug = @yydebug
-
- #
- # LR parsing algorithm main loop
- #
-
- while true do
-
- if i = action_pointer[ curstate ] then
- if read_next then
- if t != t_end then
- atmp = next_token
- tok = atmp[0]
- val = atmp[1]
- t = (token_table[tok] or t_err)
- racc_read_token( t, tok, val ) if yydebug
-
- read_next = false
- end
- end
- i += t
- if i >= 0 and act = action_table[i] and
- action_check[i] == curstate then
- else
- act = action_default[ curstate ]
- end
- else
- act = action_default[ curstate ]
- end
-
- begin
- if act > 0 and act < shift_n then
- #
- # shift
- #
-
- if @racc_error_status > 0 then
- @racc_error_status -= 1
- end
-
- vstack.push val
- if yydebug then
- tstack.push t
- racc_shift( t, tstack, vstack )
- end
-
- curstate = act
- state.push curstate
-
- read_next = true
-
- elsif act < 0 and act > -reduce_n then
- #
- # reduce
- #
-
- code = catch( :racc_jump ) {
- curstate = racc_do_reduce( arg, state, vstack, tstack, act )
- state.push curstate; false
- }
- if code then
- case code
- when 1 # yyerror
- act = -reduce_n
- user_yyerror = true
- redo
- when 2 # yyaccept
- act = shift_n
- redo
- else
- raise RuntimeError, '[Racc Bug] unknown jump code'
- end
- end
-
- elsif act == shift_n then
- #
- # accept
- #
-
- racc_accept if yydebug
- return vstack[0]
-
- elsif act == -reduce_n then
- #
- # error
- #
-
- case @racc_error_status
- when 0
- unless user_yyerror then
- nerr += 1
- on_error( t, val, vstack )
- end
- when 3
- if t == t_end then
- return nil
- end
- read_next = true
- end
- user_yyerror = false
- @racc_error_status = 3
-
- while true do
- if i = action_pointer[curstate] then
- i += t_err
- if i >= 0 and
- (act = action_table[i]) and
- action_check[i] == curstate then
- break
- end
- end
-
- return nil if state.size < 2
- state.pop
- vstack.pop
- if yydebug then
- tstack.pop
- racc_e_pop( state, tstack, vstack )
- end
- curstate = state[-1]
- end
-
- if act > 0 and act < shift_n then
- #
- # error-shift
- #
- vstack.push val
- if yydebug then
- tstack.push t_err
- racc_shift( t_err, tstack, vstack )
- end
-
- curstate = act
- state.push curstate
-
- elsif act < 0 and act > -reduce_n then
- #
- # error-reduce
- #
- code = catch( :racc_jump ) {
- curstate = racc_do_reduce( arg, state, vstack, tstack, act )
- state.push curstate; 0
- }
- unless code == 0 then
- case code
- when 1 # yyerror
- act = -reduce_n
- user_yyerror = true
- redo
- when 2 # yyaccept
- act = shift_n
- redo
- else
- raise RuntimeError, '[Racc Bug] unknown jump code'
- end
- end
-
- elsif act == shift_n then
- #
- # error-accept
- #
- racc_accept if yydebug
- return vstack[0]
-
- else
- raise RuntimeError, "[Racc Bug] wrong act value #{act.inspect}"
- end
-
- else
- raise RuntimeError, "[Racc Bug] unknown action #{act.inspect}"
- end
- end while false
-
- racc_next_state( curstate, state ) if yydebug
- end
-
- raise RuntimeError, '[Racc Bug] must not reach here'
- end
-
-
- def on_error( t, val, vstack )
- raise ParseError, "\nunexpected token #{val.inspect}"
- end
-
-
- def racc_do_reduce( arg, state, vstack, tstack, act )
- action_table, action_check, action_default, action_pointer,
- goto_table, goto_check, goto_default, goto_pointer,
- nt_base, reduce_table, token_table, shift_n, reduce_n = *arg
-
- i = act * -3
- len = reduce_table[i]
- reduce_to = reduce_table[i+1]
- method_id = reduce_table[i+2]
- void_array = []
-
- tmp_t = tstack[ -len, len ] if @yydebug
- tmp_v = vstack[ -len, len ]
- tstack[ -len, len ] = void_array if @yydebug
- vstack[ -len, len ] = void_array
- state[ -len, len ] = void_array
-
- # tstack must be renewed AFTER method call
- vstack.push( (method_id == :_reduce_none) ?
- tmp_v[0] : send(method_id, tmp_v, vstack, tmp_v[0]) )
- tstack.push reduce_to
-
- racc_reduce( tmp_t, reduce_to, tstack, vstack ) if @yydebug
-
- k1 = reduce_to - nt_base
- if i = goto_pointer[ k1 ] then
- i += state[-1]
- if i >= 0 and (curstate = goto_table[i]) and goto_check[i] == k1 then
- return curstate
- end
- end
- goto_default[ k1 ]
- end
-
- def yyerror
- throw :racc_jump, 1
- end
-
- def yyaccept
- throw :racc_jump, 2
- end
-
- def yyerrok
- @racc_error_status = 0
- end
-
-
- # for debugging output
-
- def racc_read_token( t, tok, val )
- @racc_debug_out.print 'read '
- @racc_debug_out.print tok.inspect, '(internaly ', racc_token2str(t), ') '
- @racc_debug_out.puts val.inspect
- @racc_debug_out.puts
- end
-
- def racc_shift( tok, tstack, vstack )
- @racc_debug_out.puts "shift #{racc_token2str tok}"
- racc_print_stacks tstack, vstack
- @racc_debug_out.puts
- end
-
- def racc_reduce( toks, sim, tstack, vstack )
- out = @racc_debug_out
- out.print 'reduce '
- if toks.empty? then
- out.print ' <none>'
- else
- toks.each {|t| out.print ' ', racc_token2str(t) }
- end
- out.puts " --> #{racc_token2str(sim)}"
-
- racc_print_stacks tstack, vstack
- @racc_debug_out.puts
- end
-
- def racc_accept
- @racc_debug_out.puts 'accept'
- @racc_debug_out.puts
- end
-
- def racc_e_pop( state, tstack, vstack )
- @racc_debug_out.puts 'error recovering mode: pop token'
- racc_print_states state
- racc_print_stacks tstack, vstack
- @racc_debug_out.puts
- end
-
- def racc_next_state( curstate, state )
- @racc_debug_out.puts "goto #{curstate}"
- racc_print_states state
- @racc_debug_out.puts
- end
-
- def racc_print_stacks( t, v )
- out = @racc_debug_out
- out.print ' ['
- t.each_index do |i|
- out.print ' (', racc_token2str(t[i]), ' ', v[i].inspect, ')'
- end
- out.puts ' ]'
- end
-
- def racc_print_states( s )
- out = @racc_debug_out
- out.print ' ['
- s.each {|st| out.print ' ', st }
- out.puts ' ]'
- end
-
- def racc_token2str( tok )
- type::Racc_token_to_s_table[tok] or
- raise RuntimeError, "[Racc Bug] can't convert token #{tok} to string"
- end
-
-end
-
-
-end # module Racc
diff -urN ProgrammingRuby/util/rd/rdfmt.rb ProgrammingRuby.build/util/rd/rdfmt.rb
--- ProgrammingRuby/util/rd/rdfmt.rb 2001-01-24 00:10:48 +0200
+++ ProgrammingRuby.build/util/rd/rdfmt.rb 2004-03-24 19:25:56 +0200
@@ -520,7 +520,7 @@
if substitute
@content = substitute
else
- if label.type == URL
+ if label.class == URL
@content = [StringElement.new("<URL:#{label.url}>")]
else
@content = label.element_label
@@ -534,7 +534,7 @@
end
def to_label
- if @label.type == RDLabel
+ if @label.class == RDLabel
@label.to_label
else
nil
diff -urN ProgrammingRuby/util/tidyIndex.rb ProgrammingRuby.build/util/tidyIndex.rb
--- ProgrammingRuby/util/tidyIndex.rb 2001-01-24 00:10:47 +0200
+++ ProgrammingRuby.build/util/tidyIndex.rb 2004-03-24 19:25:56 +0200
@@ -66,7 +66,7 @@
while gets
gsub(/\\protect/, '')
- if /\\indexentry\{\\Ivar\s*\{<<(.*?)>>\}\}\{(\d+)\}/
+ if /\\indexentry\{\\Ivar\s*\{<<(.*?)>>\}(\|hyperpage)?\}\{(\d+)\}/
var = $1
key = var.dup
line = $2