summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/benchmark.rb18
-rw-r--r--lib/debug.rb636
-rw-r--r--lib/delegate.rb20
-rw-r--r--lib/drb/acl.rb14
-rw-r--r--lib/drb/drb.rb8
-rw-r--r--lib/drb/extserv.rb2
-rw-r--r--lib/drb/extservm.rb2
-rw-r--r--lib/drb/ssl.rb40
-rw-r--r--lib/drb/unix.rb2
-rw-r--r--lib/e2mmap.rb54
-rw-r--r--lib/erb.rb10
-rw-r--r--lib/forwardable.rb34
-rw-r--r--lib/getoptlong.rb2
-rw-r--r--lib/ipaddr.rb20
-rw-r--r--lib/irb.rb10
-rw-r--r--lib/logger.rb20
-rw-r--r--lib/mkmf.rb108
-rw-r--r--lib/mutex_m.rb30
-rw-r--r--lib/net/ftp.rb20
-rw-r--r--lib/net/imap.rb114
-rw-r--r--lib/net/telnet.rb592
-rw-r--r--lib/prime.rb668
-rw-r--r--lib/rexml/cdata.rb18
-rw-r--r--lib/rexml/child.rb2
-rw-r--r--lib/rexml/comment.rb12
-rw-r--r--lib/rexml/document.rb20
-rw-r--r--lib/rexml/element.rb34
-rw-r--r--lib/rexml/light/node.rb14
-rw-r--r--lib/rexml/node.rb12
-rw-r--r--lib/rexml/parsers/lightparser.rb8
-rw-r--r--lib/rexml/parsers/sax2parser.rb12
-rw-r--r--lib/rexml/parsers/ultralightparser.rb8
-rw-r--r--lib/rexml/quickpath.rb90
-rw-r--r--lib/rss/maker/base.rb54
-rw-r--r--lib/rss/maker/image.rb12
-rw-r--r--lib/rss/rss.rb86
-rw-r--r--lib/scanf.rb96
-rwxr-xr-xlib/set.rb506
-rw-r--r--lib/shell.rb12
-rw-r--r--lib/shell/builtin-command.rb32
-rw-r--r--lib/shell/command-processor.rb200
-rw-r--r--lib/shell/error.rb6
-rw-r--r--lib/shell/filter.rb10
-rw-r--r--lib/shell/process-controller.rb40
-rw-r--r--lib/shell/system-command.rb12
-rw-r--r--lib/shell/version.rb6
-rw-r--r--lib/sync.rb24
-rw-r--r--lib/tempfile.rb2
-rw-r--r--lib/thread.rb8
-rw-r--r--lib/thwait.rb6
-rw-r--r--lib/un.rb64
-rw-r--r--lib/uri/common.rb10
-rw-r--r--lib/uri/generic.rb4
-rw-r--r--lib/weakref.rb12
54 files changed, 1928 insertions, 1928 deletions
diff --git a/lib/benchmark.rb b/lib/benchmark.rb
index f3d1cca8f1..84ed6c77f9 100644
--- a/lib/benchmark.rb
+++ b/lib/benchmark.rb
@@ -520,14 +520,14 @@ module Benchmark
cutime.__send__(op, x.cutime),
cstime.__send__(op, x.cstime),
real.__send__(op, x.real)
- )
+ )
else
Benchmark::Tms.new(utime.__send__(op, x),
stime.__send__(op, x),
cutime.__send__(op, x),
cstime.__send__(op, x),
real.__send__(op, x)
- )
+ )
end
end
end
@@ -548,13 +548,13 @@ if __FILE__ == $0
x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure
x.report("times:") {n.times do ; _ = "1"; end}
x.report("upto:") {1.upto(n) do ; _ = "1"; end}
-end
+ end
-benchmark do
- [
- measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure
- measure{n.times do ; _ = "1"; end},
- measure{1.upto(n) do ; _ = "1"; end}
- ]
+ benchmark do
+ [
+ measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure
+ measure{n.times do ; _ = "1"; end},
+ measure{1.upto(n) do ; _ = "1"; end}
+ ]
end
end
diff --git a/lib/debug.rb b/lib/debug.rb
index 48b28217a2..4fb9d509e7 100644
--- a/lib/debug.rb
+++ b/lib/debug.rb
@@ -82,12 +82,12 @@ class DEBUGGER__
def check_suspend
while MUTEX.synchronize {
- if @suspend_next
- DEBUGGER__.waiting.push Thread.current
- @suspend_next = false
- true
- end
- }
+ if @suspend_next
+ DEBUGGER__.waiting.push Thread.current
+ @suspend_next = false
+ true
+ end
+ }
end
end
@@ -261,11 +261,11 @@ class DEBUGGER__
set_trace false
end
end
- if trace?
- stdout.print "Trace on.\n"
- else
- stdout.print "Trace off.\n"
- end
+ if trace?
+ stdout.print "Trace on.\n"
+ else
+ stdout.print "Trace off.\n"
+ end
when /^\s*b(?:reak)?\s+(?:(.+):)?([^.:]+)$/
pos = $2
@@ -304,22 +304,22 @@ class DEBUGGER__
n += 1
end
end
- if break_points.find{|b| b[1] == 1}
- n = 1
- stdout.print "\n"
- stdout.print "Watchpoints:\n"
- for b in break_points
- if b[0] and b[1] == 1
- stdout.printf " %d %s\n", n, b[2]
+ if break_points.find{|b| b[1] == 1}
+ n = 1
+ stdout.print "\n"
+ stdout.print "Watchpoints:\n"
+ for b in break_points
+ if b[0] and b[1] == 1
+ stdout.printf " %d %s\n", n, b[2]
+ end
+ n += 1
end
- n += 1
end
- end
- if break_points.size == 0
- stdout.print "No breakpoints\n"
- else
- stdout.print "\n"
- end
+ if break_points.size == 0
+ stdout.print "No breakpoints\n"
+ else
+ stdout.print "\n"
+ end
when /^\s*del(?:ete)?(?:\s+(\d+))?$/
pos = $1
@@ -375,8 +375,8 @@ class DEBUGGER__
else
lev = 1
end
- @stop_next = lev
- prompt = false
+ @stop_next = lev
+ prompt = false
when /^\s*n(?:ext)?(?:\s+(\d+))?$/
if $1
@@ -384,9 +384,9 @@ class DEBUGGER__
else
lev = 1
end
- @stop_next = lev
- @no_step = @frames.size - frame_pos
- prompt = false
+ @stop_next = lev
+ @no_step = @frames.size - frame_pos
+ prompt = false
when /^\s*w(?:here)?$/, /^\s*f(?:rame)?$/
display_frames(frame_pos)
@@ -408,8 +408,8 @@ class DEBUGGER__
e = b + 9
end
end
- previous_line = b
- display_list(b, e, binding_file, binding_line)
+ previous_line = b
+ display_list(b, e, binding_file, binding_line)
when /^\s*up(?:\s+(\d+))?$/
previous_line = nil
@@ -549,359 +549,359 @@ Commands
h[elp] print this help
<everything else> evaluate
EOHELP
- end
+ end
- def display_expressions(binding)
- n = 1
- for d in display
- if d[0]
- stdout.printf "%d: ", n
- display_expression(d[1], binding)
+ def display_expressions(binding)
+ n = 1
+ for d in display
+ if d[0]
+ stdout.printf "%d: ", n
+ display_expression(d[1], binding)
+ end
+ n += 1
end
- n += 1
end
- end
-
- def display_expression(exp, binding)
- stdout.printf "%s = %s\n", exp, debug_silent_eval(exp, binding).to_s
- end
- def frame_set_pos(file, line)
- if @frames[0]
- @frames[0][1] = file
- @frames[0][2] = line
+ def display_expression(exp, binding)
+ stdout.printf "%s = %s\n", exp, debug_silent_eval(exp, binding).to_s
end
- end
- def display_frames(pos)
- 0.upto(@frames.size - 1) do |n|
- if n == pos
- stdout.print "--> "
- else
- stdout.print " "
+ def frame_set_pos(file, line)
+ if @frames[0]
+ @frames[0][1] = file
+ @frames[0][2] = line
end
- stdout.print format_frame(n)
end
- end
- def format_frame(pos)
- _, file, line, id = @frames[pos]
- sprintf "#%d %s:%s%s\n", pos + 1, file, line,
- (id ? ":in `#{id.id2name}'" : "")
- end
-
- def display_list(b, e, file, line)
- stdout.printf "[%d, %d] in %s\n", b, e, file
- if lines = SCRIPT_LINES__[file] and lines != true
- b.upto(e) do |n|
- if n > 0 && lines[n-1]
- if n == line
- stdout.printf "=> %d %s\n", n, lines[n-1].chomp
- else
- stdout.printf " %d %s\n", n, lines[n-1].chomp
- end
- end
+ def display_frames(pos)
+ 0.upto(@frames.size - 1) do |n|
+ if n == pos
+ stdout.print "--> "
+ else
+ stdout.print " "
+ end
+ stdout.print format_frame(n)
end
- else
- stdout.printf "No sourcefile available for %s\n", file
end
- end
- def line_at(file, line)
- lines = SCRIPT_LINES__[file]
- if lines
- return "\n" if lines == true
- line = lines[line-1]
- return "\n" unless line
- return line
+ def format_frame(pos)
+ _, file, line, id = @frames[pos]
+ sprintf "#%d %s:%s%s\n", pos + 1, file, line,
+ (id ? ":in `#{id.id2name}'" : "")
end
- return "\n"
- end
- def debug_funcname(id)
- if id.nil?
- "toplevel"
- else
- id.id2name
+ def display_list(b, e, file, line)
+ stdout.printf "[%d, %d] in %s\n", b, e, file
+ if lines = SCRIPT_LINES__[file] and lines != true
+ b.upto(e) do |n|
+ if n > 0 && lines[n-1]
+ if n == line
+ stdout.printf "=> %d %s\n", n, lines[n-1].chomp
+ else
+ stdout.printf " %d %s\n", n, lines[n-1].chomp
+ end
+ end
+ end
+ else
+ stdout.printf "No sourcefile available for %s\n", file
+ end
end
- end
- def check_break_points(file, klass, pos, binding, id)
- return false if break_points.empty?
- n = 1
- for b in break_points
- if b[0] # valid
- if b[1] == 0 # breakpoint
- if (b[2] == file and b[3] == pos) or
- (klass and b[2] == klass and b[3] == pos)
- stdout.printf "Breakpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
- return true
- end
- elsif b[1] == 1 # watchpoint
- if debug_silent_eval(b[2], binding)
- stdout.printf "Watchpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
- return true
- end
- end
+ def line_at(file, line)
+ lines = SCRIPT_LINES__[file]
+ if lines
+ return "\n" if lines == true
+ line = lines[line-1]
+ return "\n" unless line
+ return line
end
- n += 1
+ return "\n"
end
- return false
- end
- def excn_handle(file, line, id, binding)
- if $!.class <= SystemExit
- set_trace_func nil
- exit
+ def debug_funcname(id)
+ if id.nil?
+ "toplevel"
+ else
+ id.id2name
+ end
end
- if @catch and ($!.class.ancestors.find { |e| e.to_s == @catch })
- stdout.printf "%s:%d: `%s' (%s)\n", file, line, $!, $!.class
- fs = @frames.size
- tb = caller(0)[-fs..-1]
- if tb
- for i in tb
- stdout.printf "\tfrom %s\n", i
- end
+ def check_break_points(file, klass, pos, binding, id)
+ return false if break_points.empty?
+ n = 1
+ for b in break_points
+ if b[0] # valid
+ if b[1] == 0 # breakpoint
+ if (b[2] == file and b[3] == pos) or
+ (klass and b[2] == klass and b[3] == pos)
+ stdout.printf "Breakpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
+ return true
+ end
+ elsif b[1] == 1 # watchpoint
+ if debug_silent_eval(b[2], binding)
+ stdout.printf "Watchpoint %d, %s at %s:%s\n", n, debug_funcname(id), file, pos
+ return true
+ end
+ end
+ end
+ n += 1
end
- suspend_all
- debug_command(file, line, id, binding)
+ return false
end
- end
- def trace_func(event, file, line, id, binding, klass)
- Tracer.trace_func(event, file, line, id, binding, klass) if trace?
- context(Thread.current).check_suspend
- @file = file
- @line = line
- case event
- when 'line'
- frame_set_pos(file, line)
- if !@no_step or @frames.size == @no_step
- @stop_next -= 1
- @stop_next = -1 if @stop_next < 0
- elsif @frames.size < @no_step
- @stop_next = 0 # break here before leaving...
- else
- # nothing to do. skipped.
- end
- if @stop_next == 0 or check_break_points(file, nil, line, binding, id)
- @no_step = nil
- suspend_all
- debug_command(file, line, id, binding)
+ def excn_handle(file, line, id, binding)
+ if $!.class <= SystemExit
+ set_trace_func nil
+ exit
end
- when 'call'
- @frames.unshift [binding, file, line, id]
- if check_break_points(file, klass, id.id2name, binding, id)
- suspend_all
- debug_command(file, line, id, binding)
+ if @catch and ($!.class.ancestors.find { |e| e.to_s == @catch })
+ stdout.printf "%s:%d: `%s' (%s)\n", file, line, $!, $!.class
+ fs = @frames.size
+ tb = caller(0)[-fs..-1]
+ if tb
+ for i in tb
+ stdout.printf "\tfrom %s\n", i
+ end
+ end
+ suspend_all
+ debug_command(file, line, id, binding)
end
+ end
- when 'c-call'
- frame_set_pos(file, line)
+ def trace_func(event, file, line, id, binding, klass)
+ Tracer.trace_func(event, file, line, id, binding, klass) if trace?
+ context(Thread.current).check_suspend
+ @file = file
+ @line = line
+ case event
+ when 'line'
+ frame_set_pos(file, line)
+ if !@no_step or @frames.size == @no_step
+ @stop_next -= 1
+ @stop_next = -1 if @stop_next < 0
+ elsif @frames.size < @no_step
+ @stop_next = 0 # break here before leaving...
+ else
+ # nothing to do. skipped.
+ end
+ if @stop_next == 0 or check_break_points(file, nil, line, binding, id)
+ @no_step = nil
+ suspend_all
+ debug_command(file, line, id, binding)
+ end
- when 'class'
- @frames.unshift [binding, file, line, id]
+ when 'call'
+ @frames.unshift [binding, file, line, id]
+ if check_break_points(file, klass, id.id2name, binding, id)
+ suspend_all
+ debug_command(file, line, id, binding)
+ end
- when 'return', 'end'
- if @frames.size == @finish_pos
- @stop_next = 1
- @finish_pos = 0
- end
- @frames.shift
+ when 'c-call'
+ frame_set_pos(file, line)
- when 'raise'
- excn_handle(file, line, id, binding)
+ when 'class'
+ @frames.unshift [binding, file, line, id]
- end
- @last_file = file
- end
-end
+ when 'return', 'end'
+ if @frames.size == @finish_pos
+ @stop_next = 1
+ @finish_pos = 0
+ end
+ @frames.shift
-trap("INT") { DEBUGGER__.interrupt }
-@last_thread = Thread::main
-@max_thread = 1
-@thread_list = {Thread::main => 1}
-@break_points = []
-@display = []
-@waiting = []
-@stdout = STDOUT
-
-class << DEBUGGER__
- def stdout
- @stdout
- end
+ when 'raise'
+ excn_handle(file, line, id, binding)
- def stdout=(s)
- @stdout = s
+ end
+ @last_file = file
+ end
end
- def display
- @display
- end
+ trap("INT") { DEBUGGER__.interrupt }
+ @last_thread = Thread::main
+ @max_thread = 1
+ @thread_list = {Thread::main => 1}
+ @break_points = []
+ @display = []
+ @waiting = []
+ @stdout = STDOUT
- def break_points
- @break_points
- end
+ class << DEBUGGER__
+ def stdout
+ @stdout
+ end
- def waiting
- @waiting
- end
+ def stdout=(s)
+ @stdout = s
+ end
- def set_trace( arg )
- MUTEX.synchronize do
- make_thread_list
- for th, in @thread_list
- context(th).set_trace arg
- end
+ def display
+ @display
end
- arg
- end
- def set_last_thread(th)
- @last_thread = th
- end
+ def break_points
+ @break_points
+ end
- def suspend
- MUTEX.synchronize do
- make_thread_list
- for th, in @thread_list
- next if th == Thread.current
- context(th).set_suspend
- end
+ def waiting
+ @waiting
end
- # Schedule other threads to suspend as soon as possible.
- Thread.pass
- end
- def resume
- MUTEX.synchronize do
- make_thread_list
- @thread_list.each do |th,|
- next if th == Thread.current
- context(th).clear_suspend
- end
- waiting.each do |th|
- th.run
+ def set_trace( arg )
+ MUTEX.synchronize do
+ make_thread_list
+ for th, in @thread_list
+ context(th).set_trace arg
+ end
end
- waiting.clear
+ arg
end
- # Schedule other threads to restart as soon as possible.
- Thread.pass
- end
- def context(thread=Thread.current)
- c = thread[:__debugger_data__]
- unless c
- thread[:__debugger_data__] = c = Context.new
+ def set_last_thread(th)
+ @last_thread = th
end
- c
- end
-
- def interrupt
- context(@last_thread).stop_next
- end
- def get_thread(num)
- th = @thread_list.key(num)
- unless th
- @stdout.print "No thread ##{num}\n"
- throw :debug_error
+ def suspend
+ MUTEX.synchronize do
+ make_thread_list
+ for th, in @thread_list
+ next if th == Thread.current
+ context(th).set_suspend
+ end
+ end
+ # Schedule other threads to suspend as soon as possible.
+ Thread.pass
end
- th
- end
- def thread_list(num)
- th = get_thread(num)
- if th == Thread.current
- @stdout.print "+"
- else
- @stdout.print " "
+ def resume
+ MUTEX.synchronize do
+ make_thread_list
+ @thread_list.each do |th,|
+ next if th == Thread.current
+ context(th).clear_suspend
+ end
+ waiting.each do |th|
+ th.run
+ end
+ waiting.clear
+ end
+ # Schedule other threads to restart as soon as possible.
+ Thread.pass
end
- @stdout.printf "%d ", num
- @stdout.print th.inspect, "\t"
- file = context(th).instance_eval{@file}
- if file
- @stdout.print file,":",context(th).instance_eval{@line}
+
+ def context(thread=Thread.current)
+ c = thread[:__debugger_data__]
+ unless c
+ thread[:__debugger_data__] = c = Context.new
+ end
+ c
end
- @stdout.print "\n"
- end
- def thread_list_all
- for th in @thread_list.values.sort
- thread_list(th)
+ def interrupt
+ context(@last_thread).stop_next
end
- end
- def make_thread_list
- hash = {}
- for th in Thread::list
- if @thread_list.key? th
- hash[th] = @thread_list[th]
- else
- @max_thread += 1
- hash[th] = @max_thread
+ def get_thread(num)
+ th = @thread_list.key(num)
+ unless th
+ @stdout.print "No thread ##{num}\n"
+ throw :debug_error
end
+ th
end
- @thread_list = hash
- end
- def debug_thread_info(input, binding)
- case input
- when /^l(?:ist)?/
- make_thread_list
- thread_list_all
-
- when /^c(?:ur(?:rent)?)?$/
- make_thread_list
- thread_list(@thread_list[Thread.current])
-
- when /^(?:sw(?:itch)?\s+)?(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
+ def thread_list(num)
+ th = get_thread(num)
if th == Thread.current
- @stdout.print "It's the current thread.\n"
+ @stdout.print "+"
else
- thread_list(@thread_list[th])
- context(th).stop_next
- th.run
- return :cont
+ @stdout.print " "
end
+ @stdout.printf "%d ", num
+ @stdout.print th.inspect, "\t"
+ file = context(th).instance_eval{@file}
+ if file
+ @stdout.print file,":",context(th).instance_eval{@line}
+ end
+ @stdout.print "\n"
+ end
- when /^stop\s+(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- if th == Thread.current
- @stdout.print "It's the current thread.\n"
- elsif th.stop?
- @stdout.print "Already stopped.\n"
- else
- thread_list(@thread_list[th])
- context(th).suspend
+ def thread_list_all
+ for th in @thread_list.values.sort
+ thread_list(th)
end
+ end
- when /^resume\s+(\d+)/
- make_thread_list
- th = get_thread($1.to_i)
- if th == Thread.current
- @stdout.print "It's the current thread.\n"
- elsif !th.stop?
- @stdout.print "Already running."
- else
- thread_list(@thread_list[th])
- th.run
+ def make_thread_list
+ hash = {}
+ for th in Thread::list
+ if @thread_list.key? th
+ hash[th] = @thread_list[th]
+ else
+ @max_thread += 1
+ hash[th] = @max_thread
+ end
+ end
+ @thread_list = hash
+ end
+
+ def debug_thread_info(input, binding)
+ case input
+ when /^l(?:ist)?/
+ make_thread_list
+ thread_list_all
+
+ when /^c(?:ur(?:rent)?)?$/
+ make_thread_list
+ thread_list(@thread_list[Thread.current])
+
+ when /^(?:sw(?:itch)?\s+)?(\d+)/
+ make_thread_list
+ th = get_thread($1.to_i)
+ if th == Thread.current
+ @stdout.print "It's the current thread.\n"
+ else
+ thread_list(@thread_list[th])
+ context(th).stop_next
+ th.run
+ return :cont
+ end
+
+ when /^stop\s+(\d+)/
+ make_thread_list
+ th = get_thread($1.to_i)
+ if th == Thread.current
+ @stdout.print "It's the current thread.\n"
+ elsif th.stop?
+ @stdout.print "Already stopped.\n"
+ else
+ thread_list(@thread_list[th])
+ context(th).suspend
+ end
+
+ when /^resume\s+(\d+)/
+ make_thread_list
+ th = get_thread($1.to_i)
+ if th == Thread.current
+ @stdout.print "It's the current thread.\n"
+ elsif !th.stop?
+ @stdout.print "Already running."
+ else
+ thread_list(@thread_list[th])
+ th.run
+ end
end
end
end
-end
-stdout.printf "Debug.rb\n"
-stdout.printf "Emacs support available.\n\n"
-RubyVM::InstructionSequence.compile_option = {
- trace_instruction: true
-}
-set_trace_func proc { |event, file, line, id, binding, klass, *rest|
- DEBUGGER__.context.trace_func event, file, line, id, binding, klass
-}
+ stdout.printf "Debug.rb\n"
+ stdout.printf "Emacs support available.\n\n"
+ RubyVM::InstructionSequence.compile_option = {
+ trace_instruction: true
+ }
+ set_trace_func proc { |event, file, line, id, binding, klass, *rest|
+ DEBUGGER__.context.trace_func event, file, line, id, binding, klass
+ }
end
diff --git a/lib/delegate.rb b/lib/delegate.rb
index 8c93ca3ff4..2004d228c7 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -330,12 +330,12 @@ end
# :stopdoc:
def Delegator.delegating_block(mid)
lambda do |*args, &block|
- target = self.__getobj__
- begin
- target.__send__(mid, *args, &block)
- ensure
- $@.delete_if {|t| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o =~ t} if $@
- end
+ target = self.__getobj__
+ begin
+ target.__send__(mid, *args, &block)
+ ensure
+ $@.delete_if {|t| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o =~ t} if $@
+ end
end
end
# :startdoc:
@@ -368,10 +368,10 @@ def DelegateClass(superclass)
end
end
klass.define_singleton_method :public_instance_methods do |all=true|
- super(all) - superclass.protected_instance_methods
+ super(all) - superclass.protected_instance_methods
end
klass.define_singleton_method :protected_instance_methods do |all=true|
- super(all) | superclass.protected_instance_methods
+ super(all) | superclass.protected_instance_methods
end
return klass
end
@@ -405,7 +405,7 @@ if __FILE__ == $0
foo2 = SimpleDelegator.new(foo)
p foo2
foo2.instance_eval{print "foo\n"}
- p foo.test == foo2.test # => true
+ p foo.test == foo2.test # => true
p foo2.iter{[55,true]} # => true
- foo2.error # raise error!
+ foo2.error # raise error!
end
diff --git a/lib/drb/acl.rb b/lib/drb/acl.rb
index cf51687987..29a378199f 100644
--- a/lib/drb/acl.rb
+++ b/lib/drb/acl.rb
@@ -234,17 +234,17 @@ end
if __FILE__ == $0
# example
list = %w(deny all
- allow 192.168.1.1
+ allow 192.168.1.1
allow ::ffff:192.168.1.2
allow 192.168.1.3
- )
+ )
- addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
+ addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
- acl = ACL.new
- p acl.allow_addr?(addr)
+ acl = ACL.new
+ p acl.allow_addr?(addr)
- acl = ACL.new(list, ACL::DENY_ALLOW)
- p acl.allow_addr?(addr)
+ acl = ACL.new(list, ACL::DENY_ALLOW)
+ p acl.allow_addr?(addr)
end
diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb
index c93762ca74..b4ccc11306 100644
--- a/lib/drb/drb.rb
+++ b/lib/drb/drb.rb
@@ -563,7 +563,7 @@ module DRb
def load(soc) # :nodoc:
begin
- sz = soc.read(4) # sizeof (N)
+ sz = soc.read(4) # sizeof (N)
rescue
raise(DRbConnError, $!.message, $!.backtrace)
end
@@ -812,7 +812,7 @@ module DRb
[host, port, option]
else
raise(DRbBadScheme, uri) unless uri =~ /^druby:/
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
+ raise(DRbBadURI, 'can\'t parse uri:' + uri)
end
end
@@ -1117,7 +1117,7 @@ module DRb
result.backtrace.each do |x|
break if /`__send__'$/ =~ x
if /^\(druby:\/\// =~ x
- bt.push(x)
+ bt.push(x)
else
bt.push(prefix + x)
end
@@ -1584,7 +1584,7 @@ module DRb
Thread.start(@protocol.accept) do |client|
@grp.add Thread.current
Thread.current['DRb'] = { 'client' => client ,
- 'server' => self }
+ 'server' => self }
loop do
begin
succ = false
diff --git a/lib/drb/extserv.rb b/lib/drb/extserv.rb
index 4ef3253b77..bb11211cd1 100644
--- a/lib/drb/extserv.rb
+++ b/lib/drb/extserv.rb
@@ -1,6 +1,6 @@
=begin
external service
- Copyright (c) 2000,2002 Masatoshi SEKI
+ Copyright (c) 2000,2002 Masatoshi SEKI
=end
require 'drb/drb'
diff --git a/lib/drb/extservm.rb b/lib/drb/extservm.rb
index 71a5cf7a56..216fe8dcee 100644
--- a/lib/drb/extservm.rb
+++ b/lib/drb/extservm.rb
@@ -1,6 +1,6 @@
=begin
external service manager
- Copyright (c) 2000 Masatoshi SEKI
+ Copyright (c) 2000 Masatoshi SEKI
=end
require 'drb/drb'
diff --git a/lib/drb/ssl.rb b/lib/drb/ssl.rb
index e15b5915c9..17e2a73d85 100644
--- a/lib/drb/ssl.rb
+++ b/lib/drb/ssl.rb
@@ -60,10 +60,10 @@ module DRb
when 0; $stderr.putc "." # BN_generate_prime
when 1; $stderr.putc "+" # BN_generate_prime
when 2; $stderr.putc "*" # searching good prime,
- # n = #of try,
- # but also data from BN_generate_prime
+ # n = #of try,
+ # but also data from BN_generate_prime
when 3; $stderr.putc "\n" # found good prime, n==0 - p, n==1 - q,
- # but also data from BN_generate_prime
+ # but also data from BN_generate_prime
else; $stderr.putc "*" # BN_generate_prime
end
}
@@ -82,16 +82,16 @@ module DRb
cert.extensions = [
ef.create_extension("basicConstraints","CA:FALSE"),
ef.create_extension("subjectKeyIdentifier", "hash") ]
- ef.issuer_certificate = cert
- cert.add_extension(ef.create_extension("authorityKeyIdentifier",
- "keyid:always,issuer:always"))
- if comment = self[:SSLCertComment]
- cert.add_extension(ef.create_extension("nsComment", comment))
- end
- cert.sign(rsa, OpenSSL::Digest::SHA1.new)
+ ef.issuer_certificate = cert
+ cert.add_extension(ef.create_extension("authorityKeyIdentifier",
+ "keyid:always,issuer:always"))
+ if comment = self[:SSLCertComment]
+ cert.add_extension(ef.create_extension("nsComment", comment))
+ end
+ cert.sign(rsa, OpenSSL::Digest::SHA1.new)
- @cert = cert
- @pkey = rsa
+ @cert = cert
+ @pkey = rsa
end
def setup_ssl_context
@@ -117,7 +117,7 @@ module DRb
[host, port, option]
else
raise(DRbBadScheme, uri) unless uri =~ /^drbssl:/
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
+ raise(DRbBadURI, 'can\'t parse uri:' + uri)
end
end
@@ -172,13 +172,13 @@ module DRb
def accept
begin
- while true
- soc = @socket.accept
- break if (@acl ? @acl.allow_socket?(soc) : true)
- soc.close
- end
- ssl = @config.accept(soc)
- self.class.new(uri, ssl, @config, true)
+ while true
+ soc = @socket.accept
+ break if (@acl ? @acl.allow_socket?(soc) : true)
+ soc.close
+ end
+ ssl = @config.accept(soc)
+ self.class.new(uri, ssl, @config, true)
rescue OpenSSL::SSL::SSLError
warn("#{__FILE__}:#{__LINE__}: warning: #{$!.message} (#{$!.class})") if @config[:verbose]
retry
diff --git a/lib/drb/unix.rb b/lib/drb/unix.rb
index 10465987f2..549ff8cf55 100644
--- a/lib/drb/unix.rb
+++ b/lib/drb/unix.rb
@@ -14,7 +14,7 @@ module DRb
[filename, option]
else
raise(DRbBadScheme, uri) unless uri =~ /^drbunix:/
- raise(DRbBadURI, 'can\'t parse uri:' + uri)
+ raise(DRbBadURI, 'can\'t parse uri:' + uri)
end
end
diff --git a/lib/e2mmap.rb b/lib/e2mmap.rb
index 4e6d2f99b3..18a7ca003d 100644
--- a/lib/e2mmap.rb
+++ b/lib/e2mmap.rb
@@ -1,8 +1,8 @@
#
# e2mmap.rb - for ruby 1.1
-# $Release Version: 2.0$
-# $Revision: 1.10 $
-# by Keiju ISHITSUKA
+# $Release Version: 2.0$
+# $Revision: 1.10 $
+# by Keiju ISHITSUKA
#
# --
# Usage:
@@ -60,19 +60,19 @@ module Exception2MessageMapper
def bind(cl)
self.module_eval %[
def Raise(err = nil, *rest)
- Exception2MessageMapper.Raise(self.class, err, *rest)
+ Exception2MessageMapper.Raise(self.class, err, *rest)
end
alias Fail Raise
def self.included(mod)
- mod.extend Exception2MessageMapper
+ mod.extend Exception2MessageMapper
end
]
end
# Fail(err, *rest)
- # err: exception
- # rest: message arguments
+ # err: exception
+ # rest: message arguments
#
def Raise(err = nil, *rest)
E2MM.Raise(self, err, *rest)
@@ -81,19 +81,19 @@ module Exception2MessageMapper
alias fail Raise
# def_e2message(c, m)
- # c: exception
- # m: message_form
- # define exception c with message m.
+ # c: exception
+ # m: message_form
+ # define exception c with message m.
#
def def_e2message(c, m)
E2MM.def_e2message(self, c, m)
end
# def_exception(n, m, s)
- # n: exception_name
- # m: message_form
- # s: superclass(default: StandardError)
- # define exception named ``c'' with message m.
+ # n: exception_name
+ # m: message_form
+ # s: superclass(default: StandardError)
+ # define exception named ``c'' with message m.
#
def def_exception(n, m, s = StandardError)
E2MM.def_exception(self, n, m, s)
@@ -106,10 +106,10 @@ module Exception2MessageMapper
@MessageMap = {}
# E2MM.def_e2message(k, e, m)
- # k: class to define exception under.
- # e: exception
- # m: message_form
- # define exception c with message m.
+ # k: class to define exception under.
+ # e: exception
+ # m: message_form
+ # define exception c with message m.
#
def E2MM.def_e2message(k, c, m)
E2MM.instance_eval{@MessageMap[[k, c]] = m}
@@ -117,11 +117,11 @@ module Exception2MessageMapper
end
# E2MM.def_exception(k, n, m, s)
- # k: class to define exception under.
- # n: exception_name
- # m: message_form
- # s: superclass(default: StandardError)
- # define exception named ``c'' with message m.
+ # k: class to define exception under.
+ # n: exception_name
+ # m: message_form
+ # s: superclass(default: StandardError)
+ # define exception named ``c'' with message m.
#
def E2MM.def_exception(k, n, m, s = StandardError)
n = n.id2name if n.kind_of?(Fixnum)
@@ -131,9 +131,9 @@ module Exception2MessageMapper
end
# Fail(klass, err, *rest)
- # klass: class to define exception under.
- # err: exception
- # rest: message arguments
+ # klass: class to define exception under.
+ # err: exception
+ # rest: message arguments
#
def E2MM.Raise(klass = E2MM, err = nil, *rest)
if form = e2mm_message(klass, err)
@@ -141,7 +141,7 @@ module Exception2MessageMapper
#p $@
#p __FILE__
b.shift if b[0] =~ /^#{Regexp.quote(__FILE__)}:/
- raise err, sprintf(form, *rest), b
+ raise err, sprintf(form, *rest), b
else
E2MM.Fail E2MM, ErrNotRegisteredException, err.inspect
end
diff --git a/lib/erb.rb b/lib/erb.rb
index 2ee689fc77..c7b90e29c1 100644
--- a/lib/erb.rb
+++ b/lib/erb.rb
@@ -254,7 +254,7 @@
# Rails, the web application framework, uses ERB to create views.
#
class ERB
- Revision = '$Date:: $' #'
+ Revision = '$Date:: $' #'
# Returns revision information for the erb.rb module.
def self.version
@@ -726,9 +726,9 @@ class ERB
# If _trim_mode_ is passed a String containing one or more of the following
# modifiers, ERB will adjust its code generation as listed:
#
- # % enables Ruby code processing for lines beginning with %
- # <> omit newline for lines starting with <% and ending in %>
- # > omit newline for lines ending in %>
+ # % enables Ruby code processing for lines beginning with %
+ # <> omit newline for lines starting with <% and ending in %>
+ # > omit newline for lines ending in %>
#
# _eoutvar_ can be used to set the name of the variable ERB will build up
# its output in. This is useful when you need to run multiple ERB
@@ -971,7 +971,7 @@ class ERB
#
module DefMethod
public
- # define _methodname_ as instance method of current module, using ERB object or eRuby file
+ # define _methodname_ as instance method of current module, using ERB object or eRuby file
def def_erb_method(methodname, erb_or_fname)
if erb_or_fname.kind_of? String
fname = erb_or_fname
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index 192654123f..b43d00f568 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -1,9 +1,9 @@
#
# forwardable.rb -
-# $Release Version: 1.1$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
-# original definition by delegator.rb
+# $Release Version: 1.1$
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ishitsuka.com)
+# original definition by delegator.rb
# Revised by Daniel J. Berger with suggestions from Florian Gross.
#
# Documentation by James Edward Gray II and Gavin Sinclair
@@ -84,7 +84,7 @@
# def_delegator :Implementation, :service
#
# class Implementation
-# def service...
+# def service...
# end
# end
#
@@ -178,12 +178,12 @@ module Forwardable
def def_instance_delegator(accessor, method, ali = method)
line_no = __LINE__; str = %{
def #{ali}(*args, &block)
- begin
- #{accessor}.__send__(:#{method}, *args, &block)
- rescue Exception
- $@.delete_if{|s| %r"#{Regexp.quote(__FILE__)}"o =~ s} unless Forwardable::debug
- ::Kernel::raise
- end
+ begin
+ #{accessor}.__send__(:#{method}, *args, &block)
+ rescue Exception
+ $@.delete_if{|s| %r"#{Regexp.quote(__FILE__)}"o =~ s} unless Forwardable::debug
+ ::Kernel::raise
+ end
end
}
# If it's not a class or module, it's an instance
@@ -248,12 +248,12 @@ module SingleForwardable
def def_single_delegator(accessor, method, ali = method)
str = %{
def #{ali}(*args, &block)
- begin
- #{accessor}.__send__(:#{method}, *args, &block)
- rescue Exception
- $@.delete_if{|s| %r"#{Regexp.quote(__FILE__)}"o =~ s} unless Forwardable::debug
- ::Kernel::raise
- end
+ begin
+ #{accessor}.__send__(:#{method}, *args, &block)
+ rescue Exception
+ $@.delete_if{|s| %r"#{Regexp.quote(__FILE__)}"o =~ s} unless Forwardable::debug
+ ::Kernel::raise
+ end
end
}
diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb
index 30412a94c3..259382e8ec 100644
--- a/lib/getoptlong.rb
+++ b/lib/getoptlong.rb
@@ -284,7 +284,7 @@ class GetoptLong
arguments.each do |arg|
if !arg.is_a?(Array)
- raise ArgumentError, "the option list contains non-Array argument"
+ raise ArgumentError, "the option list contains non-Array argument"
end
#
diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index 87646b95ac..317f5c9458 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -72,17 +72,17 @@ end
#
# ipaddr1 = IPAddr.new "3ffe:505:2::1"
#
-# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
+# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
#
-# p ipaddr1.to_s #=> "3ffe:505:2::1"
+# p ipaddr1.to_s #=> "3ffe:505:2::1"
#
# ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
#
-# p ipaddr2.to_s #=> "3ffe:505:2::"
+# p ipaddr2.to_s #=> "3ffe:505:2::"
#
# ipaddr3 = IPAddr.new "192.168.2.0/24"
#
-# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
+# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
class IPAddr
@@ -157,8 +157,8 @@ class IPAddr
# net1 = IPAddr.new("192.168.2.0/24")
# net2 = IPAddr.new("192.168.2.100")
# net3 = IPAddr.new("192.168.3.0")
- # p net1.include?(net2) #=> true
- # p net1.include?(net3) #=> false
+ # p net1.include?(net2) #=> true
+ # p net1.include?(net3) #=> false
def include?(other)
other = coerce_other(other)
if ipv4_mapped?
@@ -473,9 +473,9 @@ class IPAddr
end
# It seems AI_NUMERICHOST doesn't do the job.
#Socket.getaddrinfo(left, nil, Socket::AF_INET6, Socket::SOCK_STREAM, nil,
- # Socket::AI_NUMERICHOST)
+ # Socket::AI_NUMERICHOST)
begin
- IPSocket.getaddress(prefix) # test if address is valid
+ IPSocket.getaddress(prefix) # test if address is valid
rescue
raise ArgumentError, "invalid address"
end
@@ -514,8 +514,8 @@ class IPAddr
def in_addr(addr)
if addr =~ /^\d+\.\d+\.\d+\.\d+$/
return addr.split('.').inject(0) { |i, s|
- i << 8 | s.to_i
- }
+ i << 8 | s.to_i
+ }
end
return nil
end
diff --git a/lib/irb.rb b/lib/irb.rb
index b11be9e8a2..c8fa04c4e5 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -1,8 +1,8 @@
#
# irb.rb - irb main module
-# $Release Version: 0.9.6 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.9.6 $
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -72,7 +72,7 @@ module IRB
ensure
irb_at_exit
end
- # print "\n"
+# print "\n"
end
def IRB.irb_at_exit
@@ -167,7 +167,7 @@ module IRB
if exc
print exc.class, ": ", exc, "\n"
if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
- !(SyntaxError === exc)
+ !(SyntaxError === exc)
irb_bug = true
else
irb_bug = false
diff --git a/lib/logger.rb b/lib/logger.rb
index 23df108b1d..6092959399 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -263,9 +263,9 @@ class Logger
alias sev_threshold level
alias sev_threshold= level=
- # Returns +true+ iff the current severity level allows for the printing of
- # +DEBUG+ messages.
- def debug?; @level <= DEBUG; end
+ # Returns +true+ iff the current severity level allows for the printing of
+ # +DEBUG+ messages.
+ def debug?; @level <= DEBUG; end
# Returns +true+ iff the current severity level allows for the printing of
# +INFO+ messages.
@@ -312,7 +312,7 @@ class Logger
@logdev = nil
if logdev
@logdev = LogDevice.new(logdev, :shift_age => shift_age,
- :shift_size => shift_size)
+ :shift_size => shift_size)
end
end
@@ -376,7 +376,7 @@ class Logger
end
@logdev.write(
format_message(format_severity(severity), Time.now, progname, message))
- true
+ true
end
alias log add
@@ -478,7 +478,7 @@ class Logger
@logdev.close if @logdev
end
- private
+private
# Severity label for logging. (max 5 char)
SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)
@@ -507,7 +507,7 @@ class Logger
msg2str(msg)]
end
- private
+ private
def format_datetime(time)
if @datetime_format.nil?
@@ -523,7 +523,7 @@ class Logger
msg
when ::Exception
"#{ msg.message } (#{ msg.class })\n" <<
- (msg.backtrace || []).join("\n")
+ (msg.backtrace || []).join("\n")
else
msg.inspect
end
@@ -585,7 +585,7 @@ class Logger
end
end
- private
+ private
def open_logfile(filename)
if (FileTest.exist?(filename))
@@ -791,7 +791,7 @@ class Logger
@log.add(severity, message, @appname, &block) if @log
end
- private
+ private
def run
# TODO: should be an NotImplementedError
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 2480cdd1b2..8cd601884c 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -299,11 +299,11 @@ end
def xsystem command, opts = nil
varpat = /\$\((\w+)\)|\$\{(\w+)\}/
- if varpat =~ command
- vars = Hash.new {|h, k| h[k] = ''; ENV[k]}
- command = command.dup
- nil while command.gsub!(varpat) {vars[$1||$2]}
- end
+ if varpat =~ command
+ vars = Hash.new {|h, k| h[k] = ''; ENV[k]}
+ command = command.dup
+ nil while command.gsub!(varpat) {vars[$1||$2]}
+ end
Logging::open do
puts command.quote
if opts and opts[:werror]
@@ -410,7 +410,7 @@ def cc_command(opt="")
'arch_hdrdir' => "#$arch_hdrdir",
'top_srcdir' => $top_srcdir.quote)
RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
- conf)
+ conf)
end
def cpp_command(outfile, opt="")
@@ -418,7 +418,7 @@ def cpp_command(outfile, opt="")
'arch_hdrdir' => "#$arch_hdrdir",
'top_srcdir' => $top_srcdir.quote)
RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
- conf)
+ conf)
end
def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
@@ -547,7 +547,7 @@ end
def try_static_assert(expr, headers = nil, opt = "", &b)
headers = cpp_include(headers)
try_compile(<<SRC, opt, &b)
- #{headers}
+#{headers}
/*top*/
int conftest_const[(#{expr}) ? 1 : -1];
SRC
@@ -616,15 +616,15 @@ def try_func(func, libs, headers = nil, &b)
decltype = proc {|x| "void ((*#{x})())"}
end
try_link(<<"SRC", libs, &b) or
- #{headers}
+#{headers}
/*top*/
- #{MAIN_DOES_NOTHING}
+#{MAIN_DOES_NOTHING}
int t() { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return 0; }
SRC
call && try_link(<<"SRC", libs, &b)
- #{headers}
+#{headers}
/*top*/
- #{MAIN_DOES_NOTHING}
+#{MAIN_DOES_NOTHING}
int t() { #{func}(); return 0; }
SRC
end
@@ -633,9 +633,9 @@ end
def try_var(var, headers = nil, &b)
headers = cpp_include(headers)
try_compile(<<"SRC", &b)
- #{headers}
+#{headers}
/*top*/
- #{MAIN_DOES_NOTHING}
+#{MAIN_DOES_NOTHING}
int t() { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
SRC
end
@@ -659,18 +659,18 @@ def egrep_cpp(pat, src, opt = "", &b)
if Regexp === pat
puts(" ruby -ne 'print if #{pat.inspect}'")
f.grep(pat) {|l|
- puts "#{f.lineno}: #{l}"
- return true
+ puts "#{f.lineno}: #{l}"
+ return true
}
false
else
puts(" egrep '#{pat}'")
begin
- stdin = $stdin.dup
- $stdin.reopen(f)
- system("egrep", pat)
+ stdin = $stdin.dup
+ $stdin.reopen(f)
+ system("egrep", pat)
ensure
- $stdin.reopen(stdin)
+ $stdin.reopen(stdin)
end
end
end
@@ -867,11 +867,11 @@ def find_library(lib, func, *paths, &b)
libs = append_library($libs, lib)
begin
until r = try_func(func, libs, &b) or paths.empty?
- $LIBPATH = libpath | [paths.shift]
+ $LIBPATH = libpath | [paths.shift]
end
if r
- $libs = libs
- libpath = nil
+ $libs = libs
+ libpath = nil
end
ensure
$LIBPATH = libpath if libpath
@@ -999,9 +999,9 @@ end
def have_struct_member(type, member, headers = nil, &b)
checking_for checking_message("#{type}.#{member}", headers) do
if try_compile(<<"SRC", &b)
- #{cpp_include(headers)}
+#{cpp_include(headers)}
/*top*/
- #{MAIN_DOES_NOTHING}
+#{MAIN_DOES_NOTHING}
int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
SRC
$defs.push(format("-DHAVE_%s_%s", type.tr_cpp, member.tr_cpp))
@@ -1019,7 +1019,7 @@ end
#
def try_type(type, headers = nil, opt = "", &b)
if try_compile(<<"SRC", opt, &b)
- #{cpp_include(headers)}
+#{cpp_include(headers)}
/*top*/
typedef #{type} conftest_type;
int conftestval[sizeof(conftest_type)?1:-1];
@@ -1077,7 +1077,7 @@ end
def try_const(const, headers = nil, opt = "", &b)
const, type = *const
if try_compile(<<"SRC", opt, &b)
- #{cpp_include(headers)}
+#{cpp_include(headers)}
/*top*/
typedef #{type || 'int'} conftest_type;
conftest_type conftestval = #{type ? '' : '(int)'}#{const};
@@ -1217,18 +1217,18 @@ def convertible_int(type, headers = nil, opts = nil, &b)
u = "unsigned " if signed > 0
prelude << "extern rbcv_typedef_ foo();"
compat = UNIVERSAL_INTS.find {|t|
- try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b)
+ try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b)
}
if compat
- macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
- conv = (compat == "long long" ? "LL" : compat.upcase)
- compat = "#{u}#{compat}"
- $defs.push(format("-DTYPEOF_%s=%s", type.tr_cpp, compat.quote))
- $defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv))
- conv = (u ? "U" : "") + conv
- $defs.push(format("-D%s2NUM=%s2NUM", macname, conv))
- $defs.push(format("-DNUM2%s=NUM2%s", macname, conv))
- compat
+ macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
+ conv = (compat == "long long" ? "LL" : compat.upcase)
+ compat = "#{u}#{compat}"
+ $defs.push(format("-DTYPEOF_%s=%s", type.tr_cpp, compat.quote))
+ $defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv))
+ conv = (u ? "U" : "") + conv
+ $defs.push(format("-D%s2NUM=%s2NUM", macname, conv))
+ $defs.push(format("-DNUM2%s=NUM2%s", macname, conv))
+ compat
end
end
end
@@ -1239,10 +1239,10 @@ end
# pointer.
def scalar_ptr_type?(type, member = nil, headers = nil, &b)
try_compile(<<"SRC", &b) # pointer
- #{cpp_include(headers)}
+#{cpp_include(headers)}
/*top*/
volatile #{type} conftestval;
- #{MAIN_DOES_NOTHING}
+#{MAIN_DOES_NOTHING}
int t() {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));}
SRC
end
@@ -1251,10 +1251,10 @@ end
# pointer.
def scalar_type?(type, member = nil, headers = nil, &b)
try_compile(<<"SRC", &b) # pointer
- #{cpp_include(headers)}
+#{cpp_include(headers)}
/*top*/
volatile #{type} conftestval;
- #{MAIN_DOES_NOTHING}
+#{MAIN_DOES_NOTHING}
int t() {return (int)(1-(conftestval#{member ? ".#{member}" : ""}));}
SRC
end
@@ -1266,7 +1266,7 @@ def have_typeof?
$typeof = %w[__typeof__ typeof].find do |t|
try_compile(<<SRC)
int rbcv_foo;
- #{t}(rbcv_foo) rbcv_bar;
+#{t}(rbcv_foo) rbcv_bar;
SRC
end
end
@@ -1644,7 +1644,7 @@ ECHO1 = $(V:1=@:)
ECHO = $(ECHO1:0=@echo)
#### Start of system configuration section. ####
- #{"top_srcdir = " + $top_srcdir.sub(%r"\A#{Regexp.quote($topdir)}/", "$(topdir)/") if $extmk}
+#{"top_srcdir = " + $top_srcdir.sub(%r"\A#{Regexp.quote($topdir)}/", "$(topdir)/") if $extmk}
srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {mkintpath(CONFIG[$1||$2])}.quote}
topdir = #{mkintpath($extmk ? CONFIG["topdir"] : $topdir).quote}
hdrdir = #{mkintpath(CONFIG["hdrdir"]).quote}
@@ -1730,7 +1730,7 @@ preload = #{defined?($preload) && $preload ? $preload.join(' ') : ''}
x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do
"!ifndef " + $1 + "\n" +
$& +
- "!endif\n"
+ "!endif\n"
end
end
end
@@ -2006,7 +2006,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
mfile.print "#{dest}: #{f}\n\t@-$(MAKEDIRS) $(@D#{sep})\n"
mfile.print "\t$(INSTALL_PROG) #{fseprepl[f]} $(@D#{sep})\n"
if defined?($installed_list)
- mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
+ mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
end
end
else
@@ -2020,17 +2020,17 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
files = install_files(mfile, i, nil, srcprefix) or next
for dir, *files in files
unless dirs.include?(dir)
- dirs << dir
- mfile.print "pre-install-rb#{sfx}: #{dir}\n"
+ dirs << dir
+ mfile.print "pre-install-rb#{sfx}: #{dir}\n"
end
for f in files
- dest = "#{dir}/#{File.basename(f)}"
- mfile.print("install-rb#{sfx}: #{dest} #{dir}\n")
- mfile.print("#{dest}: #{f}\n")
- mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D#{sep})\n")
- if defined?($installed_list) and !$extout
- mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n")
- end
+ dest = "#{dir}/#{File.basename(f)}"
+ mfile.print("install-rb#{sfx}: #{dest} #{dir}\n")
+ mfile.print("#{dest}: #{f}\n")
+ mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D#{sep})\n")
+ if defined?($installed_list) and !$extout
+ mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n")
+ end
if $extout
mfile.print("clean-rb#{sfx}::\n")
mfile.print("\t@-$(RM) #{fseprepl[dest]}\n")
diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb
index 3ff3bd1dcc..722754b8d5 100644
--- a/lib/mutex_m.rb
+++ b/lib/mutex_m.rb
@@ -1,26 +1,26 @@
#
# mutex_m.rb -
-# $Release Version: 3.0$
-# $Revision: 1.7 $
+# $Release Version: 3.0$
+# $Revision: 1.7 $
# Original from mutex.rb
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
+# by Keiju ISHITSUKA(keiju@ishitsuka.com)
# modified by matz
# patched by akira yamada
#
# --
# Usage:
-# require "mutex_m.rb"
-# obj = Object.new
-# obj.extend Mutex_m
-# ...
-# extended object can be handled like Mutex
+# require "mutex_m.rb"
+# obj = Object.new
+# obj.extend Mutex_m
+# ...
+# extended object can be handled like Mutex
# or
-# class Foo
-# include Mutex_m
-# ...
-# end
-# obj = Foo.new
-# this obj can be handled like Mutex
+# class Foo
+# include Mutex_m
+# ...
+# end
+# obj = Foo.new
+# this obj can be handled like Mutex
#
require 'thread'
@@ -52,7 +52,7 @@ module Mutex_m
defined? unlock and
defined? try_lock and
defined? synchronize)
- Mutex_m.define_aliases(singleton_class)
+ Mutex_m.define_aliases(singleton_class)
end
mu_initialize
end
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index 14c6b07826..97220cccec 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -272,7 +272,7 @@ module Net
line = getline
buff = line
if line[3] == ?-
- code = line[0, 3]
+ code = line[0, 3]
begin
line = getline
buff << "\n" << line
@@ -781,15 +781,15 @@ module Net
MDTM_REGEXP = /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ # :nodoc:
- #
- # Returns the last modification time of the (remote) file. If +local+ is
- # +true+, it is returned as a local time, otherwise it's a UTC time.
- #
- def mtime(filename, local = false)
- str = mdtm(filename)
- ary = str.scan(MDTM_REGEXP)[0].collect {|i| i.to_i}
- return local ? Time.local(*ary) : Time.gm(*ary)
- end
+ #
+ # Returns the last modification time of the (remote) file. If +local+ is
+ # +true+, it is returned as a local time, otherwise it's a UTC time.
+ #
+ def mtime(filename, local = false)
+ str = mdtm(filename)
+ ary = str.scan(MDTM_REGEXP)[0].collect {|i| i.to_i}
+ return local ? Time.local(*ary) : Time.gm(*ary)
+ end
#
# Creates a remote directory.
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index cf4754cb71..0ddb0f346f 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -1091,7 +1091,7 @@ module Net
when UntaggedResponse
record_response(resp.name, resp.data)
if resp.data.instance_of?(ResponseText) &&
- (code = resp.data.code)
+ (code = resp.data.code)
record_response(code.name, code.data)
end
if resp.name == "BYE" && @logout_command_tag.nil?
@@ -1550,7 +1550,7 @@ module Net
def ensure_nz_number(num)
if num < -1 || num == 0 || num >= 4294967296
msg = "nz_number must be non-zero unsigned 32-bit integer: " +
- num.inspect
+ num.inspect
raise DataFormatError, msg
end
end
@@ -2965,62 +2965,62 @@ module Net
return Address.new(name, route, mailbox, host)
end
- # def flag_list
- # result = []
- # match(T_LPAR)
- # while true
- # token = lookahead
- # case token.symbol
- # when T_RPAR
- # shift_token
- # break
- # when T_SPACE
- # shift_token
- # end
- # result.push(flag)
- # end
- # return result
- # end
-
- # def flag
- # token = lookahead
- # if token.symbol == T_BSLASH
- # shift_token
- # token = lookahead
- # if token.symbol == T_STAR
- # shift_token
- # return token.value.intern
- # else
- # return atom.intern
- # end
- # else
- # return atom
- # end
- # end
+# def flag_list
+# result = []
+# match(T_LPAR)
+# while true
+# token = lookahead
+# case token.symbol
+# when T_RPAR
+# shift_token
+# break
+# when T_SPACE
+# shift_token
+# end
+# result.push(flag)
+# end
+# return result
+# end
+
+# def flag
+# token = lookahead
+# if token.symbol == T_BSLASH
+# shift_token
+# token = lookahead
+# if token.symbol == T_STAR
+# shift_token
+# return token.value.intern
+# else
+# return atom.intern
+# end
+# else
+# return atom
+# end
+# end
FLAG_REGEXP = /\
(?# FLAG )\\([^\x80-\xff(){ \x00-\x1f\x7f%"\\]+)|\
(?# ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*"\\]+)/n
- def flag_list
- if @str.index(/\(([^)]*)\)/ni, @pos)
- @pos = $~.end(0)
- return $1.scan(FLAG_REGEXP).collect { |flag, atom|
- if atom
- atom
- else
- symbol = flag.capitalize.untaint.intern
- @flag_symbols[symbol] = true
- if @flag_symbols.length > IMAP.max_flag_count
- raise FlagCountError, "number of flag symbols exceeded"
- end
- symbol
- end
- }
- else
- parse_error("invalid flag list")
+ def flag_list
+ if @str.index(/\(([^)]*)\)/ni, @pos)
+ @pos = $~.end(0)
+ return $1.scan(FLAG_REGEXP).collect { |flag, atom|
+ if atom
+ atom
+ else
+ symbol = flag.capitalize.untaint.intern
+ @flag_symbols[symbol] = true
+ if @flag_symbols.length > IMAP.max_flag_count
+ raise FlagCountError, "number of flag symbols exceeded"
end
+ symbol
end
+ }
+ else
+ parse_error("invalid flag list")
+ end
+ end
def nstring
token = lookahead
@@ -3389,12 +3389,12 @@ module Net
a2 = "AUTHENTICATE:" + response[:'digest-uri']
a2 << ":00000000000000000000000000000000" if response[:qop] and response[:qop] =~ /^auth-(?:conf|int)$/
- response[:response] = Digest::MD5.hexdigest(
- [
- Digest::MD5.hexdigest(a1),
- response.values_at(:nonce, :nc, :cnonce, :qop),
- Digest::MD5.hexdigest(a2)
- ].join(':')
+ response[:response] = Digest::MD5.hexdigest(
+ [
+ Digest::MD5.hexdigest(a1),
+ response.values_at(:nonce, :nc, :cnonce, :qop),
+ Digest::MD5.hexdigest(a2)
+ ].join(':')
)
return response.keys.map {|key| qdval(key.to_s, response[key]) }.join(',')
diff --git a/lib/net/telnet.rb b/lib/net/telnet.rb
index cb517c454e..fe463c63dc 100644
--- a/lib/net/telnet.rb
+++ b/lib/net/telnet.rb
@@ -433,18 +433,18 @@ module Net
# combine CR+NULL into CR
string = string.gsub(/#{CR}#{NULL}/no, CR) if @options["Telnetmode"]
- # combine EOL into "\n"
- string = string.gsub(/#{EOL}/no, "\n") unless @options["Binmode"]
-
- # remove NULL
- string = string.gsub(/#{NULL}/no, '') unless @options["Binmode"]
-
- string.gsub(/#{IAC}(
- [#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
- [#{DO}#{DONT}#{WILL}#{WONT}]
- [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}]|
- #{SB}[^#{IAC}]*#{IAC}#{SE}
- )/xno) do
+ # combine EOL into "\n"
+ string = string.gsub(/#{EOL}/no, "\n") unless @options["Binmode"]
+
+ # remove NULL
+ string = string.gsub(/#{NULL}/no, '') unless @options["Binmode"]
+
+ string.gsub(/#{IAC}(
+ [#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]|
+ [#{DO}#{DONT}#{WILL}#{WONT}]
+ [#{OPT_BINARY}-#{OPT_NEW_ENVIRON}#{OPT_EXOPL}]|
+ #{SB}[^#{IAC}]*#{IAC}#{SE}
+ )/xno) do
if IAC == $1 # handle escaped IAC characters
IAC
elsif AYT == $1 # respond to "IAC AYT" (are you there)
@@ -464,301 +464,301 @@ module Net
elsif WILL[0] == $1[0] # respond to "IAC WILL x"
if OPT_BINARY[0] == $1[1]
self.write(IAC + DO + OPT_BINARY)
- elsif OPT_ECHO[0] == $1[1]
- self.write(IAC + DO + OPT_ECHO)
- elsif OPT_SGA[0] == $1[1]
- @telnet_option["SGA"] = true
- self.write(IAC + DO + OPT_SGA)
- else
- self.write(IAC + DONT + $1[1..1])
- end
- ''
- elsif WONT[0] == $1[0] # respond to "IAC WON'T x"
- if OPT_ECHO[0] == $1[1]
- self.write(IAC + DONT + OPT_ECHO)
- elsif OPT_SGA[0] == $1[1]
- @telnet_option["SGA"] = false
- self.write(IAC + DONT + OPT_SGA)
- else
- self.write(IAC + DONT + $1[1..1])
- end
- ''
- else
- ''
- end
- end
- end # preprocess
-
- # Read data from the host until a certain sequence is matched.
- #
- # If a block is given, the received data will be yielded as it
- # is read in (not necessarily all in one go), or nil if EOF
- # occurs before any data is received. Whether a block is given
- # or not, all data read will be returned in a single string, or again
- # nil if EOF occurs before any data is received. Note that
- # received data includes the matched sequence we were looking for.
- #
- # +options+ can be either a regular expression or a hash of options.
- # If a regular expression, this specifies the data to wait for.
- # If a hash, this can specify the following options:
- #
- # Match:: a regular expression, specifying the data to wait for.
- # Prompt:: as for Match; used only if Match is not specified.
- # String:: as for Match, except a string that will be converted
- # into a regular expression. Used only if Match and
- # Prompt are not specified.
- # Timeout:: the number of seconds to wait for data from the host
- # before raising a TimeoutError. If set to false,
- # no timeout will occur. If not specified, the
- # Timeout option value specified when this instance
- # was created will be used, or, failing that, the
- # default value of 10 seconds.
- # Waittime:: the number of seconds to wait after matching against
- # the input data to see if more data arrives. If more
- # data arrives within this time, we will judge ourselves
- # not to have matched successfully, and will continue
- # trying to match. If not specified, the Waittime option
- # value specified when this instance was created will be
- # used, or, failing that, the default value of 0 seconds,
- # which means not to wait for more input.
- # FailEOF:: if true, when the remote end closes the connection then an
- # EOFError will be raised. Otherwise, defaults to the old
- # behaviour that the function will return whatever data
- # has been received already, or nil if nothing was received.
- #
- def waitfor(options) # :yield: recvdata
- time_out = @options["Timeout"]
- waittime = @options["Waittime"]
- fail_eof = @options["FailEOF"]
-
- if options.kind_of?(Hash)
- prompt = if options.has_key?("Match")
- options["Match"]
- elsif options.has_key?("Prompt")
- options["Prompt"]
- elsif options.has_key?("String")
- Regexp.new( Regexp.quote(options["String"]) )
- end
- time_out = options["Timeout"] if options.has_key?("Timeout")
- waittime = options["Waittime"] if options.has_key?("Waittime")
- fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
- else
- prompt = options
- end
+ elsif OPT_ECHO[0] == $1[1]
+ self.write(IAC + DO + OPT_ECHO)
+ elsif OPT_SGA[0] == $1[1]
+ @telnet_option["SGA"] = true
+ self.write(IAC + DO + OPT_SGA)
+ else
+ self.write(IAC + DONT + $1[1..1])
+ end
+ ''
+ elsif WONT[0] == $1[0] # respond to "IAC WON'T x"
+ if OPT_ECHO[0] == $1[1]
+ self.write(IAC + DONT + OPT_ECHO)
+ elsif OPT_SGA[0] == $1[1]
+ @telnet_option["SGA"] = false
+ self.write(IAC + DONT + OPT_SGA)
+ else
+ self.write(IAC + DONT + $1[1..1])
+ end
+ ''
+ else
+ ''
+ end
+ end
+ end # preprocess
- if time_out == false
- time_out = nil
- end
+ # Read data from the host until a certain sequence is matched.
+ #
+ # If a block is given, the received data will be yielded as it
+ # is read in (not necessarily all in one go), or nil if EOF
+ # occurs before any data is received. Whether a block is given
+ # or not, all data read will be returned in a single string, or again
+ # nil if EOF occurs before any data is received. Note that
+ # received data includes the matched sequence we were looking for.
+ #
+ # +options+ can be either a regular expression or a hash of options.
+ # If a regular expression, this specifies the data to wait for.
+ # If a hash, this can specify the following options:
+ #
+ # Match:: a regular expression, specifying the data to wait for.
+ # Prompt:: as for Match; used only if Match is not specified.
+ # String:: as for Match, except a string that will be converted
+ # into a regular expression. Used only if Match and
+ # Prompt are not specified.
+ # Timeout:: the number of seconds to wait for data from the host
+ # before raising a TimeoutError. If set to false,
+ # no timeout will occur. If not specified, the
+ # Timeout option value specified when this instance
+ # was created will be used, or, failing that, the
+ # default value of 10 seconds.
+ # Waittime:: the number of seconds to wait after matching against
+ # the input data to see if more data arrives. If more
+ # data arrives within this time, we will judge ourselves
+ # not to have matched successfully, and will continue
+ # trying to match. If not specified, the Waittime option
+ # value specified when this instance was created will be
+ # used, or, failing that, the default value of 0 seconds,
+ # which means not to wait for more input.
+ # FailEOF:: if true, when the remote end closes the connection then an
+ # EOFError will be raised. Otherwise, defaults to the old
+ # behaviour that the function will return whatever data
+ # has been received already, or nil if nothing was received.
+ #
+ def waitfor(options) # :yield: recvdata
+ time_out = @options["Timeout"]
+ waittime = @options["Waittime"]
+ fail_eof = @options["FailEOF"]
+
+ if options.kind_of?(Hash)
+ prompt = if options.has_key?("Match")
+ options["Match"]
+ elsif options.has_key?("Prompt")
+ options["Prompt"]
+ elsif options.has_key?("String")
+ Regexp.new( Regexp.quote(options["String"]) )
+ end
+ time_out = options["Timeout"] if options.has_key?("Timeout")
+ waittime = options["Waittime"] if options.has_key?("Waittime")
+ fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
+ else
+ prompt = options
+ end
- line = ''
- buf = ''
- rest = ''
- until(prompt === line and not IO::select([@sock], nil, nil, waittime))
- unless IO::select([@sock], nil, nil, time_out)
- raise TimeoutError, "timed out while waiting for more data"
- end
- begin
- c = @sock.readpartial(1024 * 1024)
- @dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
- if @options["Telnetmode"]
- c = rest + c
- if Integer(c.rindex(/#{IAC}#{SE}/no) || 0) <
- Integer(c.rindex(/#{IAC}#{SB}/no) || 0)
- buf = preprocess(c[0 ... c.rindex(/#{IAC}#{SB}/no)])
- rest = c[c.rindex(/#{IAC}#{SB}/no) .. -1]
- elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) ||
- c.rindex(/\r\z/no)
- buf = preprocess(c[0 ... pt])
- rest = c[pt .. -1]
- else
- buf = preprocess(c)
- rest = ''
- end
- else
- # Not Telnetmode.
- #
- # We cannot use preprocess() on this data, because that
- # method makes some Telnetmode-specific assumptions.
- buf = rest + c
- rest = ''
- unless @options["Binmode"]
- if pt = buf.rindex(/\r\z/no)
- buf = buf[0 ... pt]
- rest = buf[pt .. -1]
- end
- buf.gsub!(/#{EOL}/no, "\n")
- end
- end
- @log.print(buf) if @options.has_key?("Output_log")
- line += buf
- yield buf if block_given?
- rescue EOFError # End of file reached
- raise if fail_eof
- if line == ''
- line = nil
- yield nil if block_given?
- end
- break
- end
- end
- line
- end
+ if time_out == false
+ time_out = nil
+ end
- # Write +string+ to the host.
- #
- # Does not perform any conversions on +string+. Will log +string+ to the
- # dumplog, if the Dump_log option is set.
- def write(string)
- length = string.length
- while 0 < length
- IO::select(nil, [@sock])
- @dumplog.log_dump('>', string[-length..-1]) if @options.has_key?("Dump_log")
- length -= @sock.syswrite(string[-length..-1])
+ line = ''
+ buf = ''
+ rest = ''
+ until(prompt === line and not IO::select([@sock], nil, nil, waittime))
+ unless IO::select([@sock], nil, nil, time_out)
+ raise TimeoutError, "timed out while waiting for more data"
+ end
+ begin
+ c = @sock.readpartial(1024 * 1024)
+ @dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
+ if @options["Telnetmode"]
+ c = rest + c
+ if Integer(c.rindex(/#{IAC}#{SE}/no) || 0) <
+ Integer(c.rindex(/#{IAC}#{SB}/no) || 0)
+ buf = preprocess(c[0 ... c.rindex(/#{IAC}#{SB}/no)])
+ rest = c[c.rindex(/#{IAC}#{SB}/no) .. -1]
+ elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) ||
+ c.rindex(/\r\z/no)
+ buf = preprocess(c[0 ... pt])
+ rest = c[pt .. -1]
+ else
+ buf = preprocess(c)
+ rest = ''
end
+ else
+ # Not Telnetmode.
+ #
+ # We cannot use preprocess() on this data, because that
+ # method makes some Telnetmode-specific assumptions.
+ buf = rest + c
+ rest = ''
+ unless @options["Binmode"]
+ if pt = buf.rindex(/\r\z/no)
+ buf = buf[0 ... pt]
+ rest = buf[pt .. -1]
+ end
+ buf.gsub!(/#{EOL}/no, "\n")
+ end
end
-
- # Sends a string to the host.
- #
- # This does _not_ automatically append a newline to the string. Embedded
- # newlines may be converted and telnet command sequences escaped
- # depending upon the values of telnetmode, binmode, and telnet options
- # set by the host.
- def print(string)
- string = string.gsub(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"]
-
- if @options["Binmode"]
- self.write(string)
- else
- if @telnet_option["BINARY"] and @telnet_option["SGA"]
- # IAC WILL SGA IAC DO BIN send EOL --> CR
- self.write(string.gsub(/\n/n, CR))
- elsif @telnet_option["SGA"]
- # IAC WILL SGA send EOL --> CR+NULL
- self.write(string.gsub(/\n/n, CR + NULL))
- else
- # NONE send EOL --> CR+LF
- self.write(string.gsub(/\n/n, EOL))
- end
- end
+ @log.print(buf) if @options.has_key?("Output_log")
+ line += buf
+ yield buf if block_given?
+ rescue EOFError # End of file reached
+ raise if fail_eof
+ if line == ''
+ line = nil
+ yield nil if block_given?
end
+ break
+ end
+ end
+ line
+ end
- # Sends a string to the host.
- #
- # Same as #print(), but appends a newline to the string.
- def puts(string)
- self.print(string + "\n")
- end
+ # Write +string+ to the host.
+ #
+ # Does not perform any conversions on +string+. Will log +string+ to the
+ # dumplog, if the Dump_log option is set.
+ def write(string)
+ length = string.length
+ while 0 < length
+ IO::select(nil, [@sock])
+ @dumplog.log_dump('>', string[-length..-1]) if @options.has_key?("Dump_log")
+ length -= @sock.syswrite(string[-length..-1])
+ end
+ end
- # Send a command to the host.
- #
- # More exactly, sends a string to the host, and reads in all received
- # data until is sees the prompt or other matched sequence.
- #
- # If a block is given, the received data will be yielded to it as
- # it is read in. Whether a block is given or not, the received data
- # will be return as a string. Note that the received data includes
- # the prompt and in most cases the host's echo of our command.
- #
- # +options+ is either a String, specified the string or command to
- # send to the host; or it is a hash of options. If a hash, the
- # following options can be specified:
- #
- # String:: the command or other string to send to the host.
- # Match:: a regular expression, the sequence to look for in
- # the received data before returning. If not specified,
- # the Prompt option value specified when this instance
- # was created will be used, or, failing that, the default
- # prompt of /[$%#>] \z/n.
- # Timeout:: the seconds to wait for data from the host before raising
- # a Timeout error. If not specified, the Timeout option
- # value specified when this instance was created will be
- # used, or, failing that, the default value of 10 seconds.
- #
- # The command or other string will have the newline sequence appended
- # to it.
- def cmd(options) # :yield: recvdata
- match = @options["Prompt"]
- time_out = @options["Timeout"]
- fail_eof = @options["FailEOF"]
-
- if options.kind_of?(Hash)
- string = options["String"]
- match = options["Match"] if options.has_key?("Match")
- time_out = options["Timeout"] if options.has_key?("Timeout")
- fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
- else
- string = options
- end
+ # Sends a string to the host.
+ #
+ # This does _not_ automatically append a newline to the string. Embedded
+ # newlines may be converted and telnet command sequences escaped
+ # depending upon the values of telnetmode, binmode, and telnet options
+ # set by the host.
+ def print(string)
+ string = string.gsub(/#{IAC}/no, IAC + IAC) if @options["Telnetmode"]
+
+ if @options["Binmode"]
+ self.write(string)
+ else
+ if @telnet_option["BINARY"] and @telnet_option["SGA"]
+ # IAC WILL SGA IAC DO BIN send EOL --> CR
+ self.write(string.gsub(/\n/n, CR))
+ elsif @telnet_option["SGA"]
+ # IAC WILL SGA send EOL --> CR+NULL
+ self.write(string.gsub(/\n/n, CR + NULL))
+ else
+ # NONE send EOL --> CR+LF
+ self.write(string.gsub(/\n/n, EOL))
+ end
+ end
+ end
- self.puts(string)
- if block_given?
- waitfor({"Prompt" => match, "Timeout" => time_out, "FailEOF" => fail_eof}){|c| yield c }
- else
- waitfor({"Prompt" => match, "Timeout" => time_out, "FailEOF" => fail_eof})
- end
- end
+ # Sends a string to the host.
+ #
+ # Same as #print(), but appends a newline to the string.
+ def puts(string)
+ self.print(string + "\n")
+ end
- # Login to the host with a given username and password.
- #
- # The username and password can either be provided as two string
- # arguments in that order, or as a hash with keys "Name" and
- # "Password".
- #
- # This method looks for the strings "login" and "Password" from the
- # host to determine when to send the username and password. If the
- # login sequence does not follow this pattern (for instance, you
- # are connecting to a service other than telnet), you will need
- # to handle login yourself.
- #
- # The password can be omitted, either by only
- # provided one String argument, which will be used as the username,
- # or by providing a has that has no "Password" key. In this case,
- # the method will not look for the "Password:" prompt; if it is
- # sent, it will have to be dealt with by later calls.
- #
- # The method returns all data received during the login process from
- # the host, including the echoed username but not the password (which
- # the host should not echo). If a block is passed in, this received
- # data is also yielded to the block as it is received.
- def login(options, password = nil) # :yield: recvdata
- login_prompt = /[Ll]ogin[: ]*\z/n
- password_prompt = /[Pp]ass(?:word|phrase)[: ]*\z/n
- if options.kind_of?(Hash)
- username = options["Name"]
- password = options["Password"]
- login_prompt = options["LoginPrompt"] if options["LoginPrompt"]
- password_prompt = options["PasswordPrompt"] if options["PasswordPrompt"]
- else
- username = options
- end
+ # Send a command to the host.
+ #
+ # More exactly, sends a string to the host, and reads in all received
+ # data until is sees the prompt or other matched sequence.
+ #
+ # If a block is given, the received data will be yielded to it as
+ # it is read in. Whether a block is given or not, the received data
+ # will be return as a string. Note that the received data includes
+ # the prompt and in most cases the host's echo of our command.
+ #
+ # +options+ is either a String, specified the string or command to
+ # send to the host; or it is a hash of options. If a hash, the
+ # following options can be specified:
+ #
+ # String:: the command or other string to send to the host.
+ # Match:: a regular expression, the sequence to look for in
+ # the received data before returning. If not specified,
+ # the Prompt option value specified when this instance
+ # was created will be used, or, failing that, the default
+ # prompt of /[$%#>] \z/n.
+ # Timeout:: the seconds to wait for data from the host before raising
+ # a Timeout error. If not specified, the Timeout option
+ # value specified when this instance was created will be
+ # used, or, failing that, the default value of 10 seconds.
+ #
+ # The command or other string will have the newline sequence appended
+ # to it.
+ def cmd(options) # :yield: recvdata
+ match = @options["Prompt"]
+ time_out = @options["Timeout"]
+ fail_eof = @options["FailEOF"]
+
+ if options.kind_of?(Hash)
+ string = options["String"]
+ match = options["Match"] if options.has_key?("Match")
+ time_out = options["Timeout"] if options.has_key?("Timeout")
+ fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
+ else
+ string = options
+ end
- if block_given?
- line = waitfor(login_prompt){|c| yield c }
- if password
- line += cmd({"String" => username,
- "Match" => password_prompt}){|c| yield c }
- line += cmd(password){|c| yield c }
- else
- line += cmd(username){|c| yield c }
- end
- else
- line = waitfor(login_prompt)
- if password
- line += cmd({"String" => username,
- "Match" => password_prompt})
- line += cmd(password)
- else
- line += cmd(username)
- end
- end
- line
- end
+ self.puts(string)
+ if block_given?
+ waitfor({"Prompt" => match, "Timeout" => time_out, "FailEOF" => fail_eof}){|c| yield c }
+ else
+ waitfor({"Prompt" => match, "Timeout" => time_out, "FailEOF" => fail_eof})
+ end
+ end
- # Closes the connection
- def close
- @sock.close
- end
+ # Login to the host with a given username and password.
+ #
+ # The username and password can either be provided as two string
+ # arguments in that order, or as a hash with keys "Name" and
+ # "Password".
+ #
+ # This method looks for the strings "login" and "Password" from the
+ # host to determine when to send the username and password. If the
+ # login sequence does not follow this pattern (for instance, you
+ # are connecting to a service other than telnet), you will need
+ # to handle login yourself.
+ #
+ # The password can be omitted, either by only
+ # provided one String argument, which will be used as the username,
+ # or by providing a has that has no "Password" key. In this case,
+ # the method will not look for the "Password:" prompt; if it is
+ # sent, it will have to be dealt with by later calls.
+ #
+ # The method returns all data received during the login process from
+ # the host, including the echoed username but not the password (which
+ # the host should not echo). If a block is passed in, this received
+ # data is also yielded to the block as it is received.
+ def login(options, password = nil) # :yield: recvdata
+ login_prompt = /[Ll]ogin[: ]*\z/n
+ password_prompt = /[Pp]ass(?:word|phrase)[: ]*\z/n
+ if options.kind_of?(Hash)
+ username = options["Name"]
+ password = options["Password"]
+ login_prompt = options["LoginPrompt"] if options["LoginPrompt"]
+ password_prompt = options["PasswordPrompt"] if options["PasswordPrompt"]
+ else
+ username = options
+ end
+
+ if block_given?
+ line = waitfor(login_prompt){|c| yield c }
+ if password
+ line += cmd({"String" => username,
+ "Match" => password_prompt}){|c| yield c }
+ line += cmd(password){|c| yield c }
+ else
+ line += cmd(username){|c| yield c }
+ end
+ else
+ line = waitfor(login_prompt)
+ if password
+ line += cmd({"String" => username,
+ "Match" => password_prompt})
+ line += cmd(password)
+ else
+ line += cmd(username)
+ end
+ end
+ line
+ end
+
+ # Closes the connection
+ def close
+ @sock.close
+ end
- end # class Telnet
- end # module Net
+ end # class Telnet
+end # module Net
diff --git a/lib/prime.rb b/lib/prime.rb
index 8d8598b9e1..d1164dbd05 100644
--- a/lib/prime.rb
+++ b/lib/prime.rb
@@ -99,397 +99,397 @@ class Prime
def method_added(method) # :nodoc:
(class<< self;self;end).def_delegator :instance, method
+ end
end
-end
-# Iterates the given block over all prime numbers.
-#
-# == Parameters
-# +ubound+::
-# Optional. An arbitrary positive number.
-# The upper bound of enumeration. The method enumerates
-# prime numbers infinitely if +ubound+ is nil.
-# +generator+::
-# Optional. An implementation of pseudo-prime generator.
-#
-# == Return value
-# An evaluated value of the given block at the last time.
-# Or an enumerator which is compatible to an +Enumerator+
-# if no block given.
-#
-# == Description
-# Calls +block+ once for each prime number, passing the prime as
-# a parameter.
-#
-# +ubound+::
-# Upper bound of prime numbers. The iterator stops after
-# yields all prime numbers p <= +ubound+.
-#
-# == Note
-# +Prime+.+new+ returns a object extended by +Prime+::+OldCompatibility+
-# in order to compatibility to Ruby 1.8, and +Prime+#each is overwritten
-# by +Prime+::+OldCompatibility+#+each+.
-#
-# +Prime+.+new+ is now obsolete. Use +Prime+.+instance+.+each+ or simply
-# +Prime+.+each+.
-def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
- generator.upper_bound = ubound
- generator.each(&block)
-end
+ # Iterates the given block over all prime numbers.
+ #
+ # == Parameters
+ # +ubound+::
+ # Optional. An arbitrary positive number.
+ # The upper bound of enumeration. The method enumerates
+ # prime numbers infinitely if +ubound+ is nil.
+ # +generator+::
+ # Optional. An implementation of pseudo-prime generator.
+ #
+ # == Return value
+ # An evaluated value of the given block at the last time.
+ # Or an enumerator which is compatible to an +Enumerator+
+ # if no block given.
+ #
+ # == Description
+ # Calls +block+ once for each prime number, passing the prime as
+ # a parameter.
+ #
+ # +ubound+::
+ # Upper bound of prime numbers. The iterator stops after
+ # yields all prime numbers p <= +ubound+.
+ #
+ # == Note
+ # +Prime+.+new+ returns a object extended by +Prime+::+OldCompatibility+
+ # in order to compatibility to Ruby 1.8, and +Prime+#each is overwritten
+ # by +Prime+::+OldCompatibility+#+each+.
+ #
+ # +Prime+.+new+ is now obsolete. Use +Prime+.+instance+.+each+ or simply
+ # +Prime+.+each+.
+ def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
+ generator.upper_bound = ubound
+ generator.each(&block)
+ end
-# Returns true if +value+ is prime, false for a composite.
-#
-# == Parameters
-# +value+:: an arbitrary integer to be checked.
-# +generator+:: optional. A pseudo-prime generator.
-def prime?(value, generator = Prime::Generator23.new)
- value = -value if value < 0
- return false if value < 2
- for num in generator
- q,r = value.divmod num
- return true if q < num
- return false if r == 0
+ # Returns true if +value+ is prime, false for a composite.
+ #
+ # == Parameters
+ # +value+:: an arbitrary integer to be checked.
+ # +generator+:: optional. A pseudo-prime generator.
+ def prime?(value, generator = Prime::Generator23.new)
+ value = -value if value < 0
+ return false if value < 2
+ for num in generator
+ q,r = value.divmod num
+ return true if q < num
+ return false if r == 0
+ end
end
-end
-
-# Re-composes a prime factorization and returns the product.
-#
-# == Parameters
-# +pd+:: Array of pairs of integers. The each internal
-# pair consists of a prime number -- a prime factor --
-# and a natural number -- an exponent.
-#
-# == Example
-# For [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]], it returns
-# p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
-#
-# Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
-def int_from_prime_division(pd)
- pd.inject(1){|value, (prime, index)|
- value *= prime**index
- }
-end
-# Returns the factorization of +value+.
-#
-# == Parameters
-# +value+:: An arbitrary integer.
-# +generator+:: Optional. A pseudo-prime generator.
-# +generator+.succ must return the next
-# pseudo-prime number in the ascendent
-# order. It must generate all prime numbers,
-# but may generate non prime numbers.
-#
-# === Exceptions
-# +ZeroDivisionError+:: when +value+ is zero.
-#
-# == Example
-# For an arbitrary integer
-# n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
-# prime_division(n) returns
-# [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
-#
-# Prime.prime_division(12) #=> [[2,2], [3,1]]
-#
-def prime_division(value, generator= Prime::Generator23.new)
- raise ZeroDivisionError if value == 0
- if value < 0
- value = -value
- pv = [[-1, 1]]
- else
- pv = []
+ # Re-composes a prime factorization and returns the product.
+ #
+ # == Parameters
+ # +pd+:: Array of pairs of integers. The each internal
+ # pair consists of a prime number -- a prime factor --
+ # and a natural number -- an exponent.
+ #
+ # == Example
+ # For [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]], it returns
+ # p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
+ #
+ # Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
+ def int_from_prime_division(pd)
+ pd.inject(1){|value, (prime, index)|
+ value *= prime**index
+ }
end
- for prime in generator
- count = 0
- while (value1, mod = value.divmod(prime)
- mod) == 0
- value = value1
- count += 1
+
+ # Returns the factorization of +value+.
+ #
+ # == Parameters
+ # +value+:: An arbitrary integer.
+ # +generator+:: Optional. A pseudo-prime generator.
+ # +generator+.succ must return the next
+ # pseudo-prime number in the ascendent
+ # order. It must generate all prime numbers,
+ # but may generate non prime numbers.
+ #
+ # === Exceptions
+ # +ZeroDivisionError+:: when +value+ is zero.
+ #
+ # == Example
+ # For an arbitrary integer
+ # n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
+ # prime_division(n) returns
+ # [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
+ #
+ # Prime.prime_division(12) #=> [[2,2], [3,1]]
+ #
+ def prime_division(value, generator= Prime::Generator23.new)
+ raise ZeroDivisionError if value == 0
+ if value < 0
+ value = -value
+ pv = [[-1, 1]]
+ else
+ pv = []
+ end
+ for prime in generator
+ count = 0
+ while (value1, mod = value.divmod(prime)
+ mod) == 0
+ value = value1
+ count += 1
+ end
+ if count != 0
+ pv.push [prime, count]
+ end
+ break if value1 <= prime
end
- if count != 0
- pv.push [prime, count]
+ if value > 1
+ pv.push [value, 1]
end
- break if value1 <= prime
+ return pv
end
- if value > 1
- pv.push [value, 1]
- end
- return pv
-end
-# An abstract class for enumerating pseudo-prime numbers.
-#
-# Concrete subclasses should override succ, next, rewind.
-class PseudoPrimeGenerator
- include Enumerable
+ # An abstract class for enumerating pseudo-prime numbers.
+ #
+ # Concrete subclasses should override succ, next, rewind.
+ class PseudoPrimeGenerator
+ include Enumerable
- def initialize(ubound = nil)
- @ubound = ubound
- end
+ def initialize(ubound = nil)
+ @ubound = ubound
+ end
- def upper_bound=(ubound)
- @ubound = ubound
- end
- def upper_bound
- @ubound
- end
+ def upper_bound=(ubound)
+ @ubound = ubound
+ end
+ def upper_bound
+ @ubound
+ end
- # returns the next pseudo-prime number, and move the internal
- # position forward.
- #
- # +PseudoPrimeGenerator+#succ raises +NotImplementedError+.
- def succ
- raise NotImplementedError, "need to define `succ'"
- end
+ # returns the next pseudo-prime number, and move the internal
+ # position forward.
+ #
+ # +PseudoPrimeGenerator+#succ raises +NotImplementedError+.
+ def succ
+ raise NotImplementedError, "need to define `succ'"
+ end
- # alias of +succ+.
- def next
- raise NotImplementedError, "need to define `next'"
- end
+ # alias of +succ+.
+ def next
+ raise NotImplementedError, "need to define `next'"
+ end
- # Rewinds the internal position for enumeration.
- #
- # See +Enumerator+#rewind.
- def rewind
- raise NotImplementedError, "need to define `rewind'"
- end
+ # Rewinds the internal position for enumeration.
+ #
+ # See +Enumerator+#rewind.
+ def rewind
+ raise NotImplementedError, "need to define `rewind'"
+ end
- # Iterates the given block for each prime numbers.
- def each(&block)
- return self.dup unless block
- if @ubound
- last_value = nil
- loop do
- prime = succ
- break last_value if prime > @ubound
- last_value = block.call(prime)
- end
- else
- loop do
- block.call(succ)
+ # Iterates the given block for each prime numbers.
+ def each(&block)
+ return self.dup unless block
+ if @ubound
+ last_value = nil
+ loop do
+ prime = succ
+ break last_value if prime > @ubound
+ last_value = block.call(prime)
+ end
+ else
+ loop do
+ block.call(succ)
+ end
end
end
- end
- # see +Enumerator+#with_index.
- alias with_index each_with_index
+ # see +Enumerator+#with_index.
+ alias with_index each_with_index
- # see +Enumerator+#with_object.
- def with_object(obj)
- return enum_for(:with_object) unless block_given?
- each do |prime|
- yield prime, obj
+ # see +Enumerator+#with_object.
+ def with_object(obj)
+ return enum_for(:with_object) unless block_given?
+ each do |prime|
+ yield prime, obj
+ end
end
end
-end
-# An implementation of +PseudoPrimeGenerator+.
-#
-# Uses +EratosthenesSieve+.
-class EratosthenesGenerator < PseudoPrimeGenerator
- def initialize
- @last_prime = nil
- super
- end
+ # An implementation of +PseudoPrimeGenerator+.
+ #
+ # Uses +EratosthenesSieve+.
+ class EratosthenesGenerator < PseudoPrimeGenerator
+ def initialize
+ @last_prime = nil
+ super
+ end
- def succ
- @last_prime = @last_prime ? EratosthenesSieve.instance.next_to(@last_prime) : 2
- end
- def rewind
- initialize
+ def succ
+ @last_prime = @last_prime ? EratosthenesSieve.instance.next_to(@last_prime) : 2
+ end
+ def rewind
+ initialize
+ end
+ alias next succ
end
- alias next succ
-end
-# An implementation of +PseudoPrimeGenerator+ which uses
-# a prime table generated by trial division.
-class TrialDivisionGenerator<PseudoPrimeGenerator
- def initialize
- @index = -1
- super
- end
+ # An implementation of +PseudoPrimeGenerator+ which uses
+ # a prime table generated by trial division.
+ class TrialDivisionGenerator<PseudoPrimeGenerator
+ def initialize
+ @index = -1
+ super
+ end
- def succ
- TrialDivision.instance[@index += 1]
- end
- def rewind
- initialize
+ def succ
+ TrialDivision.instance[@index += 1]
+ end
+ def rewind
+ initialize
+ end
+ alias next succ
end
- alias next succ
-end
-# Generates all integer which are greater than 2 and
-# are not divided by 2 nor 3.
-#
-# This is a pseudo-prime generator, suitable on
-# checking primality of a integer by brute force
-# method.
-class Generator23<PseudoPrimeGenerator
- def initialize
- @prime = 1
- @step = nil
- super
- end
+ # Generates all integer which are greater than 2 and
+ # are not divided by 2 nor 3.
+ #
+ # This is a pseudo-prime generator, suitable on
+ # checking primality of a integer by brute force
+ # method.
+ class Generator23<PseudoPrimeGenerator
+ def initialize
+ @prime = 1
+ @step = nil
+ super
+ end
- def succ
- loop do
- if (@step)
- @prime += @step
- @step = 6 - @step
- else
- case @prime
- when 1; @prime = 2
- when 2; @prime = 3
- when 3; @prime = 5; @step = 2
+ def succ
+ loop do
+ if (@step)
+ @prime += @step
+ @step = 6 - @step
+ else
+ case @prime
+ when 1; @prime = 2
+ when 2; @prime = 3
+ when 3; @prime = 5; @step = 2
+ end
end
+ return @prime
end
- return @prime
+ end
+ alias next succ
+ def rewind
+ initialize
end
end
- alias next succ
- def rewind
- initialize
- end
-end
-
-# Internal use. An implementation of prime table by trial division method.
-class TrialDivision
- include Singleton
- def initialize # :nodoc:
- # These are included as class variables to cache them for later uses. If memory
- # usage is a problem, they can be put in Prime#initialize as instance variables.
+ # Internal use. An implementation of prime table by trial division method.
+ class TrialDivision
+ include Singleton
- # There must be no primes between @primes[-1] and @next_to_check.
- @primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
- # @next_to_check % 6 must be 1.
- @next_to_check = 103 # @primes[-1] - @primes[-1] % 6 + 7
- @ulticheck_index = 3 # @primes.index(@primes.reverse.find {|n|
- # n < Math.sqrt(@@next_to_check) })
- @ulticheck_next_squared = 121 # @primes[@ulticheck_index + 1] ** 2
- end
+ def initialize # :nodoc:
+ # These are included as class variables to cache them for later uses. If memory
+ # usage is a problem, they can be put in Prime#initialize as instance variables.
- # Returns the cached prime numbers.
- def cache
- return @primes
- end
- alias primes cache
- alias primes_so_far cache
+ # There must be no primes between @primes[-1] and @next_to_check.
+ @primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
+ # @next_to_check % 6 must be 1.
+ @next_to_check = 103 # @primes[-1] - @primes[-1] % 6 + 7
+ @ulticheck_index = 3 # @primes.index(@primes.reverse.find {|n|
+ # n < Math.sqrt(@@next_to_check) })
+ @ulticheck_next_squared = 121 # @primes[@ulticheck_index + 1] ** 2
+ end
- # Returns the +index+th prime number.
- #
- # +index+ is a 0-based index.
- def [](index)
- while index >= @primes.length
- # Only check for prime factors up to the square root of the potential primes,
- # but without the performance hit of an actual square root calculation.
- if @next_to_check + 4 > @ulticheck_next_squared
- @ulticheck_index += 1
- @ulticheck_next_squared = @primes.at(@ulticheck_index + 1) ** 2
+ # Returns the cached prime numbers.
+ def cache
+ return @primes
+ end
+ alias primes cache
+ alias primes_so_far cache
+
+ # Returns the +index+th prime number.
+ #
+ # +index+ is a 0-based index.
+ def [](index)
+ while index >= @primes.length
+ # Only check for prime factors up to the square root of the potential primes,
+ # but without the performance hit of an actual square root calculation.
+ if @next_to_check + 4 > @ulticheck_next_squared
+ @ulticheck_index += 1
+ @ulticheck_next_squared = @primes.at(@ulticheck_index + 1) ** 2
+ end
+ # Only check numbers congruent to one and five, modulo six. All others
+
+ # are divisible by two or three. This also allows us to skip checking against
+ # two and three.
+ @primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
+ @next_to_check += 4
+ @primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
+ @next_to_check += 2
end
- # Only check numbers congruent to one and five, modulo six. All others
-
- # are divisible by two or three. This also allows us to skip checking against
- # two and three.
- @primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
- @next_to_check += 4
- @primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
- @next_to_check += 2
+ return @primes[index]
end
- return @primes[index]
end
-end
-# Internal use. An implementation of eratosthenes's sieve
-class EratosthenesSieve
- include Singleton
-
- BITS_PER_ENTRY = 16 # each entry is a set of 16-bits in a Fixnum
- NUMS_PER_ENTRY = BITS_PER_ENTRY * 2 # twiced because even numbers are omitted
- ENTRIES_PER_TABLE = 8
- NUMS_PER_TABLE = NUMS_PER_ENTRY * ENTRIES_PER_TABLE
- FILLED_ENTRY = (1 << NUMS_PER_ENTRY) - 1
-
- def initialize # :nodoc:
- # bitmap for odd prime numbers less than 256.
- # For an arbitrary odd number n, @tables[i][j][k] is
- # * 1 if n is prime,
- # * 0 if n is composite,
- # where i,j,k = indices(n)
- @tables = [[0xcb6e, 0x64b4, 0x129a, 0x816d, 0x4c32, 0x864a, 0x820d, 0x2196].freeze]
- end
+ # Internal use. An implementation of eratosthenes's sieve
+ class EratosthenesSieve
+ include Singleton
- # returns the least odd prime number which is greater than +n+.
- def next_to(n)
- n = (n-1).div(2)*2+3 # the next odd number to given n
- table_index, integer_index, bit_index = indices(n)
- loop do
- extend_table until @tables.length > table_index
- for j in integer_index...ENTRIES_PER_TABLE
- if !@tables[table_index][j].zero?
- for k in bit_index...BITS_PER_ENTRY
- return NUMS_PER_TABLE*table_index + NUMS_PER_ENTRY*j + 2*k+1 if !@tables[table_index][j][k].zero?
+ BITS_PER_ENTRY = 16 # each entry is a set of 16-bits in a Fixnum
+ NUMS_PER_ENTRY = BITS_PER_ENTRY * 2 # twiced because even numbers are omitted
+ ENTRIES_PER_TABLE = 8
+ NUMS_PER_TABLE = NUMS_PER_ENTRY * ENTRIES_PER_TABLE
+ FILLED_ENTRY = (1 << NUMS_PER_ENTRY) - 1
+
+ def initialize # :nodoc:
+ # bitmap for odd prime numbers less than 256.
+ # For an arbitrary odd number n, @tables[i][j][k] is
+ # * 1 if n is prime,
+ # * 0 if n is composite,
+ # where i,j,k = indices(n)
+ @tables = [[0xcb6e, 0x64b4, 0x129a, 0x816d, 0x4c32, 0x864a, 0x820d, 0x2196].freeze]
+ end
+
+ # returns the least odd prime number which is greater than +n+.
+ def next_to(n)
+ n = (n-1).div(2)*2+3 # the next odd number to given n
+ table_index, integer_index, bit_index = indices(n)
+ loop do
+ extend_table until @tables.length > table_index
+ for j in integer_index...ENTRIES_PER_TABLE
+ if !@tables[table_index][j].zero?
+ for k in bit_index...BITS_PER_ENTRY
+ return NUMS_PER_TABLE*table_index + NUMS_PER_ENTRY*j + 2*k+1 if !@tables[table_index][j][k].zero?
+ end
end
+ bit_index = 0
end
- bit_index = 0
+ table_index += 1; integer_index = 0
end
- table_index += 1; integer_index = 0
end
- end
- private
- # for an odd number +n+, returns (i, j, k) such that @tables[i][j][k] represents primarity of the number
- def indices(n)
- # binary digits of n: |0|1|2|3|4|5|6|7|8|9|10|11|....
- # indices: |-| k | j | i
- # because of NUMS_PER_ENTRY, NUMS_PER_TABLE
-
- k = (n & 0b00011111) >> 1
- j = (n & 0b11100000) >> 5
- i = n >> 8
- return i, j, k
- end
+ private
+ # for an odd number +n+, returns (i, j, k) such that @tables[i][j][k] represents primarity of the number
+ def indices(n)
+ # binary digits of n: |0|1|2|3|4|5|6|7|8|9|10|11|....
+ # indices: |-| k | j | i
+ # because of NUMS_PER_ENTRY, NUMS_PER_TABLE
+
+ k = (n & 0b00011111) >> 1
+ j = (n & 0b11100000) >> 5
+ i = n >> 8
+ return i, j, k
+ end
- def extend_table
- lbound = NUMS_PER_TABLE * @tables.length
- ubound = lbound + NUMS_PER_TABLE
- new_table = [FILLED_ENTRY] * ENTRIES_PER_TABLE # which represents primarity in lbound...ubound
- (3..Integer(Math.sqrt(ubound))).step(2) do |p|
- i, j, k = indices(p)
- next if @tables[i][j][k].zero?
-
- start = (lbound.div(p)+1)*p # least multiple of p which is >= lbound
- start += p if start.even?
- (start...ubound).step(2*p) do |n|
- _, j, k = indices(n)
- new_table[j] &= FILLED_ENTRY^(1<<k)
+ def extend_table
+ lbound = NUMS_PER_TABLE * @tables.length
+ ubound = lbound + NUMS_PER_TABLE
+ new_table = [FILLED_ENTRY] * ENTRIES_PER_TABLE # which represents primarity in lbound...ubound
+ (3..Integer(Math.sqrt(ubound))).step(2) do |p|
+ i, j, k = indices(p)
+ next if @tables[i][j][k].zero?
+
+ start = (lbound.div(p)+1)*p # least multiple of p which is >= lbound
+ start += p if start.even?
+ (start...ubound).step(2*p) do |n|
+ _, j, k = indices(n)
+ new_table[j] &= FILLED_ENTRY^(1<<k)
+ end
end
+ @tables << new_table.freeze
end
- @tables << new_table.freeze
end
-end
-
-# Provides a +Prime+ object with compatibility to Ruby 1.8 when instantiated via +Prime+.+new+.
-module OldCompatibility
- # Returns the next prime number and forwards internal pointer.
- def succ
- @generator.succ
- end
- alias next succ
- # Overwrites Prime#each.
- #
- # Iterates the given block over all prime numbers. Note that enumeration starts from
- # the current position of internal pointer, not rewound.
- def each(&block)
- return @generator.dup unless block_given?
- loop do
- yield succ
+ # Provides a +Prime+ object with compatibility to Ruby 1.8 when instantiated via +Prime+.+new+.
+ module OldCompatibility
+ # Returns the next prime number and forwards internal pointer.
+ def succ
+ @generator.succ
+ end
+ alias next succ
+
+ # Overwrites Prime#each.
+ #
+ # Iterates the given block over all prime numbers. Note that enumeration starts from
+ # the current position of internal pointer, not rewound.
+ def each(&block)
+ return @generator.dup unless block_given?
+ loop do
+ yield succ
+ end
end
end
end
-end
diff --git a/lib/rexml/cdata.rb b/lib/rexml/cdata.rb
index 496c6ec9fe..73358edc28 100644
--- a/lib/rexml/cdata.rb
+++ b/lib/rexml/cdata.rb
@@ -6,15 +6,15 @@ module REXML
STOP = ']]>'
ILLEGAL = /(\]\]>)/
- # Constructor. CData is data between <![CDATA[ ... ]]>
- #
- # _Examples_
- # CData.new( source )
- # CData.new( "Here is some CDATA" )
- # CData.new( "Some unprocessed data", respect_whitespace_TF, parent_element )
- def initialize( first, whitespace=true, parent=nil )
- super( first, whitespace, parent, false, true, ILLEGAL )
- end
+ # Constructor. CData is data between <![CDATA[ ... ]]>
+ #
+ # _Examples_
+ # CData.new( source )
+ # CData.new( "Here is some CDATA" )
+ # CData.new( "Some unprocessed data", respect_whitespace_TF, parent_element )
+ def initialize( first, whitespace=true, parent=nil )
+ super( first, whitespace, parent, false, true, ILLEGAL )
+ end
# Make a copy of this object
#
diff --git a/lib/rexml/child.rb b/lib/rexml/child.rb
index d0b4e352fa..bf97d5f903 100644
--- a/lib/rexml/child.rb
+++ b/lib/rexml/child.rb
@@ -7,7 +7,7 @@ module REXML
# class directly.
class Child
include Node
- attr_reader :parent # The Parent of this object
+ attr_reader :parent # The Parent of this object
# Constructor. Any inheritors of this class should call super to make
# sure this method is called.
diff --git a/lib/rexml/comment.rb b/lib/rexml/comment.rb
index d5bb65c51a..42a040c456 100644
--- a/lib/rexml/comment.rb
+++ b/lib/rexml/comment.rb
@@ -38,15 +38,15 @@ module REXML
# See REXML::Formatters
#
# output::
- # Where to write the string
+ # Where to write the string
# indent::
- # An integer. If -1, no indenting will be used; otherwise, the
- # indentation will be this number of spaces, and children will be
- # indented an additional amount.
+ # An integer. If -1, no indenting will be used; otherwise, the
+ # indentation will be this number of spaces, and children will be
+ # indented an additional amount.
# transitive::
- # Ignored by this class. The contents of comments are never modified.
+ # Ignored by this class. The contents of comments are never modified.
# ie_hack::
- # Needed for conformity to the child API, but not used by this class.
+ # Needed for conformity to the child API, but not used by this class.
def write( output, indent=-1, transitive=false, ie_hack=false )
Kernel.warn("Comment.write is deprecated. See REXML::Formatters")
indent( output, indent )
diff --git a/lib/rexml/document.rb b/lib/rexml/document.rb
index b4d7aa7e7d..96db53bdb0 100644
--- a/lib/rexml/document.rb
+++ b/lib/rexml/document.rb
@@ -165,7 +165,7 @@ module REXML
# Document.new("<a><b/></a>").serialize( tr )
#
# output::
- # output an object which supports '<< string'; this is where the
+ # output an object which supports '<< string'; this is where the
# document will be written.
# indent::
# An integer. If -1, no indenting will be used; otherwise, the
@@ -188,15 +188,15 @@ module REXML
output = Output.new( output, xml_decl.encoding )
end
formatter = if indent > -1
- if transitive
- require "rexml/formatters/transitive"
- REXML::Formatters::Transitive.new( indent, ie_hack )
- else
- REXML::Formatters::Pretty.new( indent, ie_hack )
- end
- else
- REXML::Formatters::Default.new( ie_hack )
- end
+ if transitive
+ require "rexml/formatters/transitive"
+ REXML::Formatters::Transitive.new( indent, ie_hack )
+ else
+ REXML::Formatters::Pretty.new( indent, ie_hack )
+ end
+ else
+ REXML::Formatters::Default.new( ie_hack )
+ end
formatter.write( self, output )
end
diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb
index 0650824d6d..5991859a78 100644
--- a/lib/rexml/element.rb
+++ b/lib/rexml/element.rb
@@ -20,7 +20,7 @@ module REXML
class Element < Parent
include Namespace
- UNDEFINED = "UNDEFINED"; # The default name
+ UNDEFINED = "UNDEFINED"; # The default name
# Mechanisms for accessing attributes and child elements of this
# element.
@@ -297,7 +297,7 @@ module REXML
el = @elements.add(element)
attrs.each do |key, value|
el.attributes[key]=value
- end if attrs.kind_of? Hash
+ end if attrs.kind_of? Hash
el
end
@@ -667,7 +667,7 @@ module REXML
#
# Writes out this element, and recursively, all children.
# output::
- # output an object which supports '<< string'; this is where the
+ # output an object which supports '<< string'; this is where the
# document will be written.
# indent::
# An integer. If -1, no indenting will be used; otherwise, the
@@ -690,15 +690,15 @@ module REXML
def write(output=$stdout, indent=-1, transitive=false, ie_hack=false)
Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters")
formatter = if indent > -1
- if transitive
- require "rexml/formatters/transitive"
- REXML::Formatters::Transitive.new( indent, ie_hack )
- else
- REXML::Formatters::Pretty.new( indent, ie_hack )
- end
- else
- REXML::Formatters::Default.new( ie_hack )
- end
+ if transitive
+ require "rexml/formatters/transitive"
+ REXML::Formatters::Transitive.new( indent, ie_hack )
+ else
+ REXML::Formatters::Pretty.new( indent, ie_hack )
+ end
+ else
+ REXML::Formatters::Default.new( ie_hack )
+ end
formatter.write( self, output )
end
@@ -778,7 +778,7 @@ module REXML
else
return XPath::first( @element, index )
#{ |element|
- # return element if element.kind_of? Element
+ # return element if element.kind_of? Element
#}
#return nil
end
@@ -1086,7 +1086,7 @@ module REXML
# doc.root.attributes['foo'] = '4'
# doc.root.attributes['x:foo'] = nil
def []=( name, value )
- if value.nil? # Delete the named attribute
+ if value.nil? # Delete the named attribute
attr = get_attribute(name)
delete attr
return
@@ -1116,8 +1116,8 @@ module REXML
value.prefix != "xmlns" and old_attr.prefix != "xmlns" and
@element.namespace( old_attr.prefix ) ==
@element.namespace( value.prefix )
- store value.name, { old_attr.prefix => old_attr,
- value.prefix => value }
+ store value.name, { old_attr.prefix => old_attr,
+ value.prefix => value }
else
store value.name, value
end
@@ -1236,7 +1236,7 @@ module REXML
( !namespace.empty? || !attribute.fully_expanded_name.index(':') )
# foo will match xmlns:foo, but only if foo isn't also an attribute
result = attribute if !result or !namespace.empty? or
- !attribute.fully_expanded_name.index(':')
+ !attribute.fully_expanded_name.index(':')
end
}
result
diff --git a/lib/rexml/light/node.rb b/lib/rexml/light/node.rb
index 07effd0705..0a896c83dc 100644
--- a/lib/rexml/light/node.rb
+++ b/lib/rexml/light/node.rb
@@ -1,13 +1,13 @@
require 'rexml/xmltokens'
# [ :element, parent, name, attributes, children* ]
-# a = Node.new
-# a << "B" # => <a>B</a>
-# a.b # => <a>B<b/></a>
-# a.b[1] # => <a>B<b/><b/><a>
-# a.b[1]["x"] = "y" # => <a>B<b/><b x="y"/></a>
-# a.b[0].c # => <a>B<b><c/></b><b x="y"/></a>
-# a.b.c << "D" # => <a>B<b><c>D</c></b><b x="y"/></a>
+ # a = Node.new
+ # a << "B" # => <a>B</a>
+ # a.b # => <a>B<b/></a>
+ # a.b[1] # => <a>B<b/><b/><a>
+ # a.b[1]["x"] = "y" # => <a>B<b/><b x="y"/></a>
+ # a.b[0].c # => <a>B<b><c/></b><b x="y"/></a>
+ # a.b.c << "D" # => <a>B<b><c>D</c></b><b x="y"/></a>
module REXML
module Light
# Represents a tagged XML element. Elements are characterized by
diff --git a/lib/rexml/node.rb b/lib/rexml/node.rb
index dabf7a931b..cab6e9fddb 100644
--- a/lib/rexml/node.rb
+++ b/lib/rexml/node.rb
@@ -36,12 +36,12 @@ module REXML
end
def indent to, ind
- if @parent and @parent.context and not @parent.context[:indentstyle].nil? then
- indentstyle = @parent.context[:indentstyle]
- else
- indentstyle = ' '
- end
- to << indentstyle*ind unless ind<1
+ if @parent and @parent.context and not @parent.context[:indentstyle].nil? then
+ indentstyle = @parent.context[:indentstyle]
+ else
+ indentstyle = ' '
+ end
+ to << indentstyle*ind unless ind<1
end
def parent?
diff --git a/lib/rexml/parsers/lightparser.rb b/lib/rexml/parsers/lightparser.rb
index 43633f7347..81041681c2 100644
--- a/lib/rexml/parsers/lightparser.rb
+++ b/lib/rexml/parsers/lightparser.rb
@@ -44,10 +44,10 @@ module REXML
end
# An element is an array. The array contains:
- # 0 The parent element
- # 1 The tag name
- # 2 A hash of attributes
- # 3..-1 The child elements
+ # 0 The parent element
+ # 1 The tag name
+ # 2 A hash of attributes
+ # 3..-1 The child elements
# An element is an array of size > 3
# Text is a String
# PIs are [ :processing_instruction, target, data ]
diff --git a/lib/rexml/parsers/sax2parser.rb b/lib/rexml/parsers/sax2parser.rb
index 7c0311aa2e..0661af37aa 100644
--- a/lib/rexml/parsers/sax2parser.rb
+++ b/lib/rexml/parsers/sax2parser.rb
@@ -28,15 +28,15 @@ module REXML
# Listen arguments:
#
# Symbol, Array, Block
- # Listen to Symbol events on Array elements
+ # Listen to Symbol events on Array elements
# Symbol, Block
# Listen to Symbol events
# Array, Listener
- # Listen to all events on Array elements
+ # Listen to all events on Array elements
# Array, Block
- # Listen to :start_element events on Array elements
+ # Listen to :start_element events on Array elements
# Listener
- # Listen to All events
+ # Listen to All events
#
# Symbol can be one of: :start_element, :end_element,
# :start_prefix_mapping, :end_prefix_mapping, :characters,
@@ -209,7 +209,7 @@ module REXML
((name.nil? and match.nil?) or match.nil? or (
(name == match) or
(match.kind_of? Regexp and name =~ match)
- )
+ )
)
)
end.collect{|x| x[-1]}
@@ -222,7 +222,7 @@ module REXML
((name.nil? and match.nil?) or match.nil? or (
(name == match) or
(match.kind_of? Regexp and name =~ match)
- )
+ )
)
)
end.collect{|x| x[-1]}
diff --git a/lib/rexml/parsers/ultralightparser.rb b/lib/rexml/parsers/ultralightparser.rb
index 7460845881..7dd8172802 100644
--- a/lib/rexml/parsers/ultralightparser.rb
+++ b/lib/rexml/parsers/ultralightparser.rb
@@ -42,10 +42,10 @@ module REXML
end
# An element is an array. The array contains:
- # 0 The parent element
- # 1 The tag name
- # 2 A hash of attributes
- # 3..-1 The child elements
+ # 0 The parent element
+ # 1 The tag name
+ # 2 A hash of attributes
+ # 3..-1 The child elements
# An element is an array of size > 3
# Text is a String
# PIs are [ :processing_instruction, target, data ]
diff --git a/lib/rexml/quickpath.rb b/lib/rexml/quickpath.rb
index 4925f6a133..9bec2158dd 100644
--- a/lib/rexml/quickpath.rb
+++ b/lib/rexml/quickpath.rb
@@ -49,20 +49,20 @@ module REXML
def QuickPath::filter elements, path
return elements if path.nil? or path == '' or elements.size == 0
case path
- when /^\/\//u # Descendant
+ when /^\/\//u # Descendant
return axe( elements, "descendant-or-self", $' )
- when /^\/?\b(\w[-\w]*)\b::/u # Axe
+ when /^\/?\b(\w[-\w]*)\b::/u # Axe
return axe( elements, $1, $' )
- when /^\/(?=\b([:!\w][-\.\w]*:)?[-!\*\.\w]*\b([^:(]|$)|\*)/u # Child
- rest = $'
- results = []
- elements.each do |element|
- results |= filter( element.to_a, rest )
- end
- return results
- when /^\/?(\w[-\w]*)\(/u # / Function
- return function( elements, $1, $' )
- when Namespace::NAMESPLIT # Element name
+ when /^\/(?=\b([:!\w][-\.\w]*:)?[-!\*\.\w]*\b([^:(]|$)|\*)/u # Child
+ rest = $'
+ results = []
+ elements.each do |element|
+ results |= filter( element.to_a, rest )
+ end
+ return results
+ when /^\/?(\w[-\w]*)\(/u # / Function
+ return function( elements, $1, $' )
+ when Namespace::NAMESPLIT # Element name
name = $2
ns = $1
rest = $'
@@ -79,22 +79,22 @@ module REXML
matches |= predicate( element.to_a, path[1..-1] ) if element.kind_of? Element
end
return matches
- when /^\[/u # Predicate
+ when /^\[/u # Predicate
return predicate( elements, path )
- when /^\/?\.\.\./u # Ancestor
+ when /^\/?\.\.\./u # Ancestor
return axe( elements, "ancestor", $' )
- when /^\/?\.\./u # Parent
+ when /^\/?\.\./u # Parent
return filter( elements.collect{|e|e.parent}, $' )
- when /^\/?\./u # Self
+ when /^\/?\./u # Self
return filter( elements, $' )
- when /^\*/u # Any
+ when /^\*/u # Any
results = []
elements.each do |element|
results |= filter( [element], $' ) if element.kind_of? Element
#if element.kind_of? Element
- # children = element.to_a
- # children.delete_if { |child| !child.kind_of?(Element) }
- # results |= filter( children, $' )
+ # children = element.to_a
+ # children.delete_if { |child| !child.kind_of?(Element) }
+ # results |= filter( children, $' )
#end
end
return results
@@ -132,7 +132,7 @@ module REXML
matches = filter(elements.collect{|element| element.parent}.uniq, rest)
when "following-sibling"
matches = filter(elements.collect{|element| element.next_sibling}.uniq,
- rest)
+ rest)
when "previous-sibling"
matches = filter(elements.collect{|element|
element.previous_sibling}.uniq, rest )
@@ -174,32 +174,32 @@ module REXML
predicate.gsub!(
/#{OPERAND_}\s*([<>=])\s*#{OPERAND_}\s*([<>=])\s*#{OPERAND_}/u,
'\1 \2 \3 and \3 \4 \5' )
- # Let's do some Ruby trickery to avoid some work:
- predicate.gsub!( /&/u, "&&" )
- predicate.gsub!( /=/u, "==" )
- predicate.gsub!( /@(\w[-\w.]*)/u, 'attribute("\1")' )
- predicate.gsub!( /\bmod\b/u, "%" )
- predicate.gsub!( /\b(\w[-\w.]*\()/u ) {
- fname = $1
- fname.gsub( /-/u, "_" )
- }
+ # Let's do some Ruby trickery to avoid some work:
+ predicate.gsub!( /&/u, "&&" )
+ predicate.gsub!( /=/u, "==" )
+ predicate.gsub!( /@(\w[-\w.]*)/u, 'attribute("\1")' )
+ predicate.gsub!( /\bmod\b/u, "%" )
+ predicate.gsub!( /\b(\w[-\w.]*\()/u ) {
+ fname = $1
+ fname.gsub( /-/u, "_" )
+ }
- Functions.pair = [ 0, elements.size ]
- results = []
- elements.each do |element|
- Functions.pair[0] += 1
- Functions.node = element
- res = eval( predicate )
- case res
- when true
- results << element
- when Fixnum
- results << element if Functions.pair[0] == res
- when String
- results << element
- end
+ Functions.pair = [ 0, elements.size ]
+ results = []
+ elements.each do |element|
+ Functions.pair[0] += 1
+ Functions.node = element
+ res = eval( predicate )
+ case res
+ when true
+ results << element
+ when Fixnum
+ results << element if Functions.pair[0] == res
+ when String
+ results << element
end
- return filter( results, rest )
+ end
+ return filter( results, rest )
end
def QuickPath::attribute( name )
diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb
index 78fc9f8acb..fa2b02d101 100644
--- a/lib/rss/maker/base.rb
+++ b/lib/rss/maker/base.rb
@@ -51,7 +51,7 @@ module RSS
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
def new_#{name}
- #{name} = self.class::#{klass_name}.new(@maker)
+ #{name} = self.class::#{klass_name}.new(@maker)
@#{plural} << #{name}
if block_given?
yield #{name}
@@ -63,14 +63,14 @@ module RSS
def to_feed(*args)
@#{plural}.each do |#{name}|
- #{name}.to_feed(*args)
+ #{name}.to_feed(*args)
end
end
def replace(elements)
@#{plural}.replace(elements.to_a)
end
- EOC
+ EOC
end
def def_classed_element_without_accessor(name, class_name=nil)
@@ -88,7 +88,7 @@ module RSS
def make_#{name}
self.class::#{class_name}.new(@maker)
end
- EOC
+ EOC
end
def def_classed_element(name, class_name=nil, attribute_name=nil)
@@ -106,7 +106,7 @@ module RSS
def #{name}=(new_value)
@#{name}.#{attribute_name} = new_value
end
- EOC
+ EOC
else
attr_reader name
end
@@ -126,17 +126,17 @@ module RSS
end
module_eval(<<-EOC, __FILE__, __LINE__ + 1)
def #{name}
- #{local_variable_name} = #{plural_name}.first
- #{local_variable_name} ? #{local_variable_name}.#{attribute} : nil
+ #{local_variable_name} = #{plural_name}.first
+ #{local_variable_name} ? #{local_variable_name}.#{attribute} : nil
end
def #{name}=(#{new_value_variable_name})
- #{local_variable_name} =
- #{plural_name}.first || #{plural_name}.new_#{new_name}
- #{additional_setup_code}
- #{local_variable_name}.#{attribute} = #{new_value_variable_name}
+ #{local_variable_name} =
+ #{plural_name}.first || #{plural_name}.new_#{new_name}
+ #{additional_setup_code}
+ #{local_variable_name}.#{attribute} = #{new_value_variable_name}
end
- EOC
+ EOC
end
def def_other_element(name)
@@ -153,7 +153,7 @@ module RSS
current.#{name} = @#{name}
end
end
- EOC
+ EOC
end
def def_csv_element(name, type=nil)
@@ -167,7 +167,7 @@ module RSS
def #{name}=(value)
@#{name} = Utils::CSV.parse(value)#{converter}
end
- EOC
+ EOC
end
end
@@ -308,7 +308,7 @@ module RSS
def ensure_xml_content(content)
xhtml_uri = ::RSS::Atom::XHTML_URI
unless content.is_a?(RSS::XML::Element) and
- ["div", xhtml_uri] == [content.name, content.uri]
+ ["div", xhtml_uri] == [content.name, content.uri]
children = content
children = [children] unless content.is_a?(Array)
children = set_xhtml_uri_as_default_uri(children)
@@ -331,7 +331,7 @@ module RSS
def set_xhtml_uri_as_default_uri(children)
children.collect do |child|
if child.is_a?(RSS::XML::Element) and
- child.prefix.nil? and child.uri.nil?
+ child.prefix.nil? and child.uri.nil?
RSS::XML::Element.new(child.name, nil, ::RSS::Atom::XHTML_URI,
child.attributes.dup,
set_xhtml_uri_as_default_uri(child.children))
@@ -385,7 +385,7 @@ module RSS
}
_language = language
if _language and
- !dc_languages.any? {|dc_language| dc_language.value == _language}
+ !dc_languages.any? {|dc_language| dc_language.value == _language}
dc_language = self.class::DublinCoreLanguages::DublinCoreLanguage.new(self)
dc_language.value = _language.dup
dc_languages.unshift(dc_language)
@@ -417,7 +417,7 @@ module RSS
def make_#{element}
self.class::#{Utils.to_class_name(element)}.new(self)
end
- EOC
+ EOC
end
attr_reader :feed_version
@@ -500,9 +500,9 @@ module RSS
end
[
- ["link", "href", Proc.new {|target,| "#{target}.href = 'self'"}],
- ["author", "name"],
- ["contributor", "name"],
+ ["link", "href", Proc.new {|target,| "#{target}.href = 'self'"}],
+ ["author", "name"],
+ ["contributor", "name"],
].each do |name, attribute, additional_setup_maker|
def_classed_elements(name, attribute, &additional_setup_maker)
end
@@ -511,7 +511,7 @@ module RSS
managingEditor webMaster rating docs ttl).each do |element|
attr_accessor element
add_need_initialize_variable(element)
- end
+ end
%w(date lastBuildDate).each do |date_element|
attr_reader date_element
@@ -713,9 +713,9 @@ module RSS
end
[
- ["author", "name"],
- ["link", "href", Proc.new {|target,| "#{target}.href = 'alternate'"}],
- ["contributor", "name"],
+ ["author", "name"],
+ ["link", "href", Proc.new {|target,| "#{target}.href = 'alternate'"}],
+ ["contributor", "name"],
].each do |name, attribute|
def_classed_elements(name, attribute)
end
@@ -795,10 +795,10 @@ module RSS
%w(authors categories contributors generator icon
logo rights subtitle title).each do |name|
def_classed_element(name)
- end
+ end
[
- ["link", "href"],
+ ["link", "href"],
].each do |name, attribute|
def_classed_elements(name, attribute)
end
diff --git a/lib/rss/maker/image.rb b/lib/rss/maker/image.rb
index 6b8f4f8e57..06084b4af4 100644
--- a/lib/rss/maker/image.rb
+++ b/lib/rss/maker/image.rb
@@ -17,7 +17,7 @@ module RSS
class ImageItem < ImageItemBase
DublinCoreModel.install_dublin_core(self)
end
- EOC
+EOC
end
class ImageItemBase < Base
@@ -29,9 +29,9 @@ module RSS
add_need_initialize_variable("image_width")
add_need_initialize_variable("image_height")
alias width= image_width=
- alias width image_width
+ alias width image_width
alias height= image_height=
- alias height image_height
+ alias height image_height
def have_required_values?
@about
@@ -73,9 +73,9 @@ module RSS
alias size image_size
alias size= image_size=
- def have_required_values?
- @about and @image_size
- end
+ def have_required_values?
+ @about and @image_size
+ end
def to_feed(feed, current)
if current.respond_to?(:image_favicon=) and have_required_values?
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index 5be6a2fbaa..3d90d54912 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -5,27 +5,27 @@ class Time
unless respond_to?(:w3cdtf)
def w3cdtf(date)
if /\A\s*
- (-?\d+)-(\d\d)-(\d\d)
- (?:T
- (\d\d):(\d\d)(?::(\d\d))?
- (\.\d+)?
- (Z|[+-]\d\d:\d\d)?)?
- \s*\z/ix =~ date and (($5 and $8) or (!$5 and !$8))
- datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i]
- usec = 0
- usec = $7.to_f * 1000000 if $7
- zone = $8
- if zone
- off = zone_offset(zone, datetime[0])
- datetime = apply_offset(*(datetime + [off]))
- datetime << usec
- time = Time.utc(*datetime)
- time.localtime unless zone_utc?(zone)
- time
- else
- datetime << usec
- Time.local(*datetime)
- end
+ (-?\d+)-(\d\d)-(\d\d)
+ (?:T
+ (\d\d):(\d\d)(?::(\d\d))?
+ (\.\d+)?
+ (Z|[+-]\d\d:\d\d)?)?
+ \s*\z/ix =~ date and (($5 and $8) or (!$5 and !$8))
+ datetime = [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i]
+ usec = 0
+ usec = $7.to_f * 1000000 if $7
+ zone = $8
+ if zone
+ off = zone_offset(zone, datetime[0])
+ datetime = apply_offset(*(datetime + [off]))
+ datetime << usec
+ time = Time.utc(*datetime)
+ time.localtime unless zone_utc?(zone)
+ time
+ else
+ datetime << usec
+ Time.local(*datetime)
+ end
else
raise ArgumentError.new("invalid date: #{date.inspect}")
end
@@ -209,7 +209,7 @@ module RSS
else
''
end
- EOC
+EOC
end
end
alias_method(:install_have_attribute_element, :install_have_child_element)
@@ -230,7 +230,7 @@ module RSS
rv << value if /\\A\\s*\\z/ !~ value
end
rv.join("\n")
- EOC
+EOC
end
end
@@ -259,12 +259,12 @@ module RSS
else
rv << value
end
- rv << "</#{elem_name}>"
+ rv << "</#{elem_name}>"
rv
else
''
end
- EOC
+EOC
end
end
@@ -290,12 +290,12 @@ module RSS
else
rv << value
end
- rv << "</#{elem_name}>"
+ rv << "</#{elem_name}>"
rv
else
''
end
- EOC
+EOC
end
end
@@ -307,10 +307,10 @@ module RSS
add_to_element_method(method_name)
module_eval(<<-EOC, *get_file_and_line_from_caller(2))
def #{method_name}(need_convert=true, indent='')
- #{yield(name, elem_name)}
+ #{yield(name, elem_name)}
end
private :#{method_name}
- EOC
+EOC
end
def inherit_convert_attr_reader(*attrs)
@@ -323,14 +323,14 @@ module RSS
def #{attr}
if @#{attr}
- #{attr}_without_inherit
+ #{attr}_without_inherit
elsif @parent
@parent.#{attr}
else
nil
end
end
- EOC
+EOC
end
end
@@ -351,7 +351,7 @@ module RSS
"\#{base}\#{value}"
end
end
- EOC
+EOC
end
end
@@ -362,7 +362,7 @@ module RSS
def #{attr}
convert(@#{attr})
end
- EOC
+EOC
end
end
@@ -408,7 +408,7 @@ module RSS
@#{attr}.join(#{separator.dump})
end
end
- EOC
+ EOC
end
end
@@ -448,7 +448,7 @@ module RSS
end
end
- EOC
+EOC
end
def integer_writer(name, disp_name=name)
@@ -468,7 +468,7 @@ module RSS
end
end
end
- EOC
+EOC
end
def positive_integer_writer(name, disp_name=name)
@@ -490,7 +490,7 @@ module RSS
end
end
end
- EOC
+EOC
end
def boolean_writer(name, disp_name=name)
@@ -510,7 +510,7 @@ module RSS
end
end
end
- EOC
+EOC
end
def text_type_writer(name, disp_name=name)
@@ -522,7 +522,7 @@ module RSS
end
@#{name} = new_value
end
- EOC
+EOC
end
def content_writer(name, disp_name=name)
@@ -536,7 +536,7 @@ module RSS
@#{name}.content = new_value
end
end
- EOC
+EOC
end
def yes_clean_other_writer(name, disp_name=name)
@@ -603,7 +603,7 @@ module RSS
end
end
alias_method(:set_#{accessor_name}, :#{accessor_name}=)
- EOC
+EOC
end
end
@@ -630,7 +630,7 @@ module RSS
value = __send__(var)
next if value.nil?
if value.respond_to?("setup_maker") and
- !not_need_to_call_setup_maker_variables.include?(var)
+ !not_need_to_call_setup_maker_variables.include?(var)
value.setup_maker(target)
else
setter = "#{var}="
@@ -1173,7 +1173,7 @@ module RSS
else
if name == tag
if models[i+1] and models[i+1][0] != name and
- tags and tags.first == name
+ tags and tags.first == name
raise TooMuchTagError.new(name, tag_name)
end
else
diff --git a/lib/scanf.rb b/lib/scanf.rb
index ced14a8964..15def5aa12 100644
--- a/lib/scanf.rb
+++ b/lib/scanf.rb
@@ -506,28 +506,28 @@ module Scanf
class FormatString
attr_reader :string_left, :last_spec_tried,
- :last_match_tried, :matched_count, :space
+ :last_match_tried, :matched_count, :space
SPECIFIERS = 'diuXxofFeEgGscaA'
REGEX = /
- # possible space, followed by...
- (?:\s*
- # percent sign, followed by...
- %
- # another percent sign, or...
- (?:%|
- # optional assignment suppression flag
- \*?
- # optional maximum field width
- \d*
- # named character class, ...
- (?:\[\[:\w+:\]\]|
- # traditional character class, or...
- \[[^\]]*\]|
- # specifier letter.
- [#{SPECIFIERS}])))|
- # or miscellaneous characters
- [^%\s]+/ix
+ # possible space, followed by...
+ (?:\s*
+ # percent sign, followed by...
+ %
+ # another percent sign, or...
+ (?:%|
+ # optional assignment suppression flag
+ \*?
+ # optional maximum field width
+ \d*
+ # named character class, ...
+ (?:\[\[:\w+:\]\]|
+ # traditional character class, or...
+ \[[^\]]*\]|
+ # specifier letter.
+ [#{SPECIFIERS}])))|
+ # or miscellaneous characters
+ [^%\s]+/ix
def initialize(str)
@specs = []
@@ -578,33 +578,33 @@ end
class IO
- # The trick here is doing a match where you grab one *line*
- # of input at a time. The linebreak may or may not occur
- # at the boundary where the string matches a format specifier.
- # And if it does, some rule about whitespace may or may not
- # be in effect...
- #
- # That's why this is much more elaborate than the string
- # version.
- #
- # For each line:
- # Match succeeds (non-emptily)
- # and the last attempted spec/string sub-match succeeded:
- #
- # could the last spec keep matching?
- # yes: save interim results and continue (next line)
- #
- # The last attempted spec/string did not match:
- #
- # are we on the next-to-last spec in the string?
- # yes:
- # is fmt_string.string_left all spaces?
- # yes: does current spec care about input space?
- # yes: fatal failure
- # no: save interim results and continue
- # no: continue [this state could be analyzed further]
- #
- #
+# The trick here is doing a match where you grab one *line*
+# of input at a time. The linebreak may or may not occur
+# at the boundary where the string matches a format specifier.
+# And if it does, some rule about whitespace may or may not
+# be in effect...
+#
+# That's why this is much more elaborate than the string
+# version.
+#
+# For each line:
+# Match succeeds (non-emptily)
+# and the last attempted spec/string sub-match succeeded:
+#
+# could the last spec keep matching?
+# yes: save interim results and continue (next line)
+#
+# The last attempted spec/string did not match:
+#
+# are we on the next-to-last spec in the string?
+# yes:
+# is fmt_string.string_left all spaces?
+# yes: does current spec care about input space?
+# yes: fatal failure
+# no: save interim results and continue
+# no: continue [this state could be analyzed further]
+#
+#
def scanf(str,&b)
return block_scanf(str,&b) if b
@@ -671,8 +671,8 @@ class IO
def block_scanf(str)
final = []
- # Sub-ideal, since another FS gets created in scanf.
- # But used here to determine the number of specifiers.
+# Sub-ideal, since another FS gets created in scanf.
+# But used here to determine the number of specifiers.
fstr = Scanf::FormatString.new(str)
last_spec = fstr.last_spec
begin
diff --git a/lib/set.rb b/lib/set.rb
index 51f4e70ce2..43edc7557a 100755
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -92,19 +92,19 @@ class Set
@hash = orig.instance_eval{@hash}.dup
end
- def freeze # :nodoc:
+ def freeze # :nodoc:
super
@hash.freeze
self
end
- def taint # :nodoc:
+ def taint # :nodoc:
super
@hash.taint
self
end
- def untaint # :nodoc:
+ def untaint # :nodoc:
super
@hash.untaint
self
@@ -325,161 +325,161 @@ class Set
def |(enum)
dup.merge(enum)
end
- alias + | ##
- alias union | ##
+ alias + | ##
+ alias union | ##
- # Returns a new set built by duplicating the set, removing every
- # element that appears in the given enumerable object.
- def -(enum)
- dup.subtract(enum)
- end
- alias difference - ##
-
- # Returns a new set containing elements common to the set and the
- # given enumerable object.
- def &(enum)
- n = self.class.new
- do_with_enum(enum) { |o| n.add(o) if include?(o) }
- n
- end
- alias intersection & ##
+ # Returns a new set built by duplicating the set, removing every
+ # element that appears in the given enumerable object.
+ def -(enum)
+ dup.subtract(enum)
+ end
+ alias difference - ##
- # Returns a new set containing elements exclusive between the set
- # and the given enumerable object. (set ^ enum) is equivalent to
- # ((set | enum) - (set & enum)).
- def ^(enum)
- n = Set.new(enum)
- each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
- n
-end
+ # Returns a new set containing elements common to the set and the
+ # given enumerable object.
+ def &(enum)
+ n = self.class.new
+ do_with_enum(enum) { |o| n.add(o) if include?(o) }
+ n
+ end
+ alias intersection & ##
-# Returns true if two sets are equal. The equality of each couple
-# of elements is defined according to Object#eql?.
-def ==(other)
- if self.equal?(other)
- true
- elsif other.instance_of?(self.class)
- @hash == other.instance_variable_get(:@hash)
- elsif other.is_a?(Set) && self.size == other.size
- other.all? { |o| @hash.include?(o) }
- else
- false
+ # Returns a new set containing elements exclusive between the set
+ # and the given enumerable object. (set ^ enum) is equivalent to
+ # ((set | enum) - (set & enum)).
+ def ^(enum)
+ n = Set.new(enum)
+ each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
+ n
+ end
+
+ # Returns true if two sets are equal. The equality of each couple
+ # of elements is defined according to Object#eql?.
+ def ==(other)
+ if self.equal?(other)
+ true
+ elsif other.instance_of?(self.class)
+ @hash == other.instance_variable_get(:@hash)
+ elsif other.is_a?(Set) && self.size == other.size
+ other.all? { |o| @hash.include?(o) }
+ else
+ false
+ end
end
-end
-def hash # :nodoc:
- @hash.hash
-end
+ def hash # :nodoc:
+ @hash.hash
+ end
-def eql?(o) # :nodoc:
- return false unless o.is_a?(Set)
- @hash.eql?(o.instance_eval{@hash})
-end
+ def eql?(o) # :nodoc:
+ return false unless o.is_a?(Set)
+ @hash.eql?(o.instance_eval{@hash})
+ end
-# Classifies the set by the return value of the given block and
-# returns a hash of {value => set of elements} pairs. The block is
-# called once for each element of the set, passing the element as
-# parameter.
-#
-# e.g.:
-#
-# require 'set'
-# files = Set.new(Dir.glob("*.rb"))
-# hash = files.classify { |f| File.mtime(f).year }
-# p hash # => {2000=>#<Set: {"a.rb", "b.rb"}>,
-# # 2001=>#<Set: {"c.rb", "d.rb", "e.rb"}>,
-# # 2002=>#<Set: {"f.rb"}>}
-def classify # :yields: o
- block_given? or return enum_for(__method__)
-
- h = {}
-
- each { |i|
- x = yield(i)
- (h[x] ||= self.class.new).add(i)
- }
-
- h
-end
+ # Classifies the set by the return value of the given block and
+ # returns a hash of {value => set of elements} pairs. The block is
+ # called once for each element of the set, passing the element as
+ # parameter.
+ #
+ # e.g.:
+ #
+ # require 'set'
+ # files = Set.new(Dir.glob("*.rb"))
+ # hash = files.classify { |f| File.mtime(f).year }
+ # p hash # => {2000=>#<Set: {"a.rb", "b.rb"}>,
+ # # 2001=>#<Set: {"c.rb", "d.rb", "e.rb"}>,
+ # # 2002=>#<Set: {"f.rb"}>}
+ def classify # :yields: o
+ block_given? or return enum_for(__method__)
-# Divides the set into a set of subsets according to the commonality
-# defined by the given block.
-#
-# If the arity of the block is 2, elements o1 and o2 are in common
-# if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are
-# in common if block.call(o1) == block.call(o2).
-#
-# e.g.:
-#
-# require 'set'
-# numbers = Set[1, 3, 4, 6, 9, 10, 11]
-# set = numbers.divide { |i,j| (i - j).abs == 1 }
-# p set # => #<Set: {#<Set: {1}>,
-# # #<Set: {11, 9, 10}>,
-# # #<Set: {3, 4}>,
-# # #<Set: {6}>}>
-def divide(&func)
- func or return enum_for(__method__)
-
- if func.arity == 2
- require 'tsort'
-
- class << dig = {} # :nodoc:
- include TSort
-
- alias tsort_each_node each_key
- def tsort_each_child(node, &block)
- fetch(node).each(&block)
- end
- end
+ h = {}
- each { |u|
- dig[u] = a = []
- each{ |v| func.call(u, v) and a << v }
+ each { |i|
+ x = yield(i)
+ (h[x] ||= self.class.new).add(i)
}
- set = Set.new()
- dig.each_strongly_connected_component { |css|
- set.add(self.class.new(css))
- }
- set
- else
- Set.new(classify(&func).values)
+ h
end
-end
-InspectKey = :__inspect_key__ # :nodoc:
+ # Divides the set into a set of subsets according to the commonality
+ # defined by the given block.
+ #
+ # If the arity of the block is 2, elements o1 and o2 are in common
+ # if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are
+ # in common if block.call(o1) == block.call(o2).
+ #
+ # e.g.:
+ #
+ # require 'set'
+ # numbers = Set[1, 3, 4, 6, 9, 10, 11]
+ # set = numbers.divide { |i,j| (i - j).abs == 1 }
+ # p set # => #<Set: {#<Set: {1}>,
+ # # #<Set: {11, 9, 10}>,
+ # # #<Set: {3, 4}>,
+ # # #<Set: {6}>}>
+ def divide(&func)
+ func or return enum_for(__method__)
+
+ if func.arity == 2
+ require 'tsort'
+
+ class << dig = {} # :nodoc:
+ include TSort
+
+ alias tsort_each_node each_key
+ def tsort_each_child(node, &block)
+ fetch(node).each(&block)
+ end
+ end
-# Returns a string containing a human-readable representation of the
-# set. ("#<Set: {element1, element2, ...}>")
-def inspect
- ids = (Thread.current[InspectKey] ||= [])
+ each { |u|
+ dig[u] = a = []
+ each{ |v| func.call(u, v) and a << v }
+ }
- if ids.include?(object_id)
- return sprintf('#<%s: {...}>', self.class.name)
+ set = Set.new()
+ dig.each_strongly_connected_component { |css|
+ set.add(self.class.new(css))
+ }
+ set
+ else
+ Set.new(classify(&func).values)
+ end
end
- begin
- ids << object_id
- return sprintf('#<%s: {%s}>', self.class, to_a.inspect[1..-2])
- ensure
- ids.pop
+ InspectKey = :__inspect_key__ # :nodoc:
+
+ # Returns a string containing a human-readable representation of the
+ # set. ("#<Set: {element1, element2, ...}>")
+ def inspect
+ ids = (Thread.current[InspectKey] ||= [])
+
+ if ids.include?(object_id)
+ return sprintf('#<%s: {...}>', self.class.name)
+ end
+
+ begin
+ ids << object_id
+ return sprintf('#<%s: {%s}>', self.class, to_a.inspect[1..-2])
+ ensure
+ ids.pop
+ end
end
-end
-def pretty_print(pp) # :nodoc:
- pp.text sprintf('#<%s: {', self.class.name)
- pp.nest(1) {
- pp.seplist(self) { |o|
- pp.pp o
- }
- }
- pp.text "}>"
-end
+ def pretty_print(pp) # :nodoc:
+ pp.text sprintf('#<%s: {', self.class.name)
+ pp.nest(1) {
+ pp.seplist(self) { |o|
+ pp.pp o
+ }
+ }
+ pp.text "}>"
+ end
-def pretty_print_cycle(pp) # :nodoc:
- pp.text sprintf('#<%s: {%s}>', self.class.name, empty? ? '' : '...')
-end
+ def pretty_print_cycle(pp) # :nodoc:
+ pp.text sprintf('#<%s: {%s}>', self.class.name, empty? ? '' : '...')
+ end
end
#
@@ -515,11 +515,11 @@ class SortedSet < Set
@@setup = false
class << self
- def [](*ary) # :nodoc:
+ def [](*ary) # :nodoc:
new(ary)
end
- def setup # :nodoc:
+ def setup # :nodoc:
@@setup and return
module_eval {
@@ -531,78 +531,78 @@ class SortedSet < Set
require 'rbtree'
module_eval %{
- def initialize(*args, &block)
- @hash = RBTree.new
- super
- end
-
- def add(o)
- o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>"
- super
- end
- alias << add
+ def initialize(*args, &block)
+ @hash = RBTree.new
+ super
+ end
+
+ def add(o)
+ o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>"
+ super
+ end
+ alias << add
}
rescue LoadError
module_eval %{
- def initialize(*args, &block)
- @keys = nil
- super
- end
-
- def clear
- @keys = nil
- super
- end
-
- def replace(enum)
- @keys = nil
- super
- end
-
- def add(o)
- o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>"
- @keys = nil
- super
- end
- alias << add
-
- def delete(o)
- @keys = nil
- @hash.delete(o)
- self
- end
-
- def delete_if
+ def initialize(*args, &block)
+ @keys = nil
+ super
+ end
+
+ def clear
+ @keys = nil
+ super
+ end
+
+ def replace(enum)
+ @keys = nil
+ super
+ end
+
+ def add(o)
+ o.respond_to?(:<=>) or raise ArgumentError, "value must respond to <=>"
+ @keys = nil
+ super
+ end
+ alias << add
+
+ def delete(o)
+ @keys = nil
+ @hash.delete(o)
+ self
+ end
+
+ def delete_if
block_given? or return enum_for(__method__)
- n = @hash.size
- super
- @keys = nil if @hash.size != n
- self
- end
-
- def keep_if
- block_given? or return enum_for(__method__)
- n = @hash.size
- super
- @keys = nil if @hash.size != n
- self
- end
-
- def merge(enum)
- @keys = nil
- super
- end
+ n = @hash.size
+ super
+ @keys = nil if @hash.size != n
+ self
+ end
- def each
- block_given? or return enum_for(__method__)
- to_a.each { |o| yield(o) }
- self
- end
-
- def to_a
- (@keys = @hash.keys).sort! unless @keys
- @keys
- end
+ def keep_if
+ block_given? or return enum_for(__method__)
+ n = @hash.size
+ super
+ @keys = nil if @hash.size != n
+ self
+ end
+
+ def merge(enum)
+ @keys = nil
+ super
+ end
+
+ def each
+ block_given? or return enum_for(__method__)
+ to_a.each { |o| yield(o) }
+ self
+ end
+
+ def to_a
+ (@keys = @hash.keys).sort! unless @keys
+ @keys
+ end
}
end
@@ -610,7 +610,7 @@ class SortedSet < Set
end
end
- def initialize(*args, &block) # :nodoc:
+ def initialize(*args, &block) # :nodoc:
SortedSet.setup
initialize(*args, &block)
end
@@ -657,54 +657,54 @@ end
#
# if @proc.arity == 2
# instance_eval %{
-# def add(o)
-# @hash[o] = true if @proc.call(self, o)
-# self
-# end
-# alias << add
+# def add(o)
+# @hash[o] = true if @proc.call(self, o)
+# self
+# end
+# alias << add
#
-# def add?(o)
-# if include?(o) || !@proc.call(self, o)
-# nil
-# else
-# @hash[o] = true
-# self
-# end
-# end
+# def add?(o)
+# if include?(o) || !@proc.call(self, o)
+# nil
+# else
+# @hash[o] = true
+# self
+# end
+# end
#
-# def replace(enum)
-# enum.respond_to?(:each) or raise ArgumentError, "value must be enumerable"
-# clear
-# enum.each_entry { |o| add(o) }
+# def replace(enum)
+# enum.respond_to?(:each) or raise ArgumentError, "value must be enumerable"
+# clear
+# enum.each_entry { |o| add(o) }
#
-# self
-# end
+# self
+# end
#
-# def merge(enum)
-# enum.respond_to?(:each) or raise ArgumentError, "value must be enumerable"
-# enum.each_entry { |o| add(o) }
+# def merge(enum)
+# enum.respond_to?(:each) or raise ArgumentError, "value must be enumerable"
+# enum.each_entry { |o| add(o) }
#
-# self
-# end
+# self
+# end
# }
# else
# instance_eval %{
-# def add(o)
+# def add(o)
# if @proc.call(o)
-# @hash[o] = true
+# @hash[o] = true
# end
-# self
-# end
-# alias << add
+# self
+# end
+# alias << add
#
-# def add?(o)
-# if include?(o) || !@proc.call(o)
-# nil
-# else
-# @hash[o] = true
-# self
-# end
-# end
+# def add?(o)
+# if include?(o) || !@proc.call(o)
+# nil
+# else
+# @hash[o] = true
+# self
+# end
+# end
# }
# end
#
@@ -838,10 +838,10 @@ class TC_Set < Test::Unit::TestCase
5,
Set[7,
Set[0]
- ],
- Set[6,2],
- 1
- ],
+ ],
+ Set[6,2],
+ 1
+ ],
3,
Set[3,4]
]
@@ -1020,8 +1020,8 @@ class TC_Set < Test::Unit::TestCase
assert_nothing_raised {
set.each { |o|
- ary.delete(o) or raise "unexpected element: #{o}"
- }
+ ary.delete(o) or raise "unexpected element: #{o}"
+ }
ary.empty? or raise "forgotten elements: #{ary.join(', ')}"
}
@@ -1168,8 +1168,8 @@ class TC_Set < Test::Unit::TestCase
set2 = Set["a", "b", set1]
set1 = set1.add(set1.clone)
- # assert_equal(set1, set2)
- # assert_equal(set2, set1)
+# assert_equal(set1, set2)
+# assert_equal(set2, set1)
assert_equal(set2, set2.clone)
assert_equal(set1.clone, set1)
diff --git a/lib/shell.rb b/lib/shell.rb
index 7d6b91c933..9e409a1004 100644
--- a/lib/shell.rb
+++ b/lib/shell.rb
@@ -1,8 +1,8 @@
#
# shell.rb -
-# $Release Version: 0.7 $
-# $Revision: 1.9 $
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.7 $
+# $Revision: 1.9 $
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -25,7 +25,7 @@ class Shell
include Error
extend Exception2MessageMapper
- # @cascade = true
+# @cascade = true
# debug: true -> normal debug
# debug: 1 -> eval definition debug
# debug: 2 -> detail inspect debug
@@ -41,7 +41,7 @@ class Shell
attr_accessor :cascade, :debug, :verbose
- # alias cascade? cascade
+# alias cascade? cascade
alias debug? debug
alias verbose? verbose
@verbose = true
@@ -286,7 +286,7 @@ class Shell
yield mes if iterator?
if _head
_head = false
- # "shell" " + mes
+# "shell" " + mes
prefix + mes
else
" "* prefix.size + mes
diff --git a/lib/shell/builtin-command.rb b/lib/shell/builtin-command.rb
index f0e064e435..b1ca5c38f6 100644
--- a/lib/shell/builtin-command.rb
+++ b/lib/shell/builtin-command.rb
@@ -1,8 +1,8 @@
#
# shell/builtin-command.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.7 $
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -83,19 +83,19 @@ class Shell
end
end
- # class Sort < Cat
- # def initialize(sh, *filenames)
- # super
- # end
- #
- # def each(rs = nil)
- # ary = []
- # super{|l| ary.push l}
- # for l in ary.sort!
- # yield l
- # end
- # end
- # end
+# class Sort < Cat
+# def initialize(sh, *filenames)
+# super
+# end
+#
+# def each(rs = nil)
+# ary = []
+# super{|l| ary.push l}
+# for l in ary.sort!
+# yield l
+# end
+# end
+# end
class AppendIO < BuiltInCommand
def initialize(sh, io, filter)
diff --git a/lib/shell/command-processor.rb b/lib/shell/command-processor.rb
index d7a48232cb..ae157eba5c 100644
--- a/lib/shell/command-processor.rb
+++ b/lib/shell/command-processor.rb
@@ -1,8 +1,8 @@
#
# shell/command-controller.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.7 $
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -19,7 +19,7 @@ require "shell/builtin-command"
class Shell
class CommandProcessor
- # include Error
+# include Error
#
# initialize of Shell and related classes.
@@ -68,9 +68,9 @@ class Shell
#
# CommandProcessor#expand_path(path)
- # path: String
- # return: String
- # returns the absolute path for <path>
+ # path: String
+ # return: String
+ # returns the absolute path for <path>
#
def expand_path(path)
@shell.expand_path(path)
@@ -86,13 +86,13 @@ class Shell
# -
#
# CommandProcessor#foreach(path, rs)
- # path: String
- # rs: String - record separator
- # iterator
- # Same as:
- # File#foreach (when path is file)
- # Dir#foreach (when path is directory)
- # path is relative to pwd
+ # path: String
+ # rs: String - record separator
+ # iterator
+ # Same as:
+ # File#foreach (when path is file)
+ # Dir#foreach (when path is directory)
+ # path is relative to pwd
#
def foreach(path = nil, *rs)
path = "." unless path
@@ -107,13 +107,13 @@ class Shell
#
# CommandProcessor#open(path, mode)
- # path: String
- # mode: String
- # return: File or Dir
- # Same as:
- # File#open (when path is file)
- # Dir#open (when path is directory)
- # mode has an effect only when path is a file
+ # path: String
+ # mode: String
+ # return: File or Dir
+ # Same as:
+ # File#open (when path is file)
+ # Dir#open (when path is directory)
+ # mode has an effect only when path is a file
#
def open(path, mode = nil, perm = 0666, &b)
path = expand_path(path)
@@ -136,9 +136,9 @@ class Shell
#
# CommandProcessor#unlink(path)
- # same as:
- # Dir#unlink (when path is directory)
- # File#unlink (when path is file)
+ # same as:
+ # Dir#unlink (when path is directory)
+ # File#unlink (when path is file)
#
def unlink(path)
@shell.check_point
@@ -155,19 +155,19 @@ class Shell
#
# CommandProcessor#test(command, file1, file2)
# CommandProcessor#[command, file1, file2]
- # command: char or String or Symbol
- # file1: String
- # file2: String(optional)
- # return: Boolean
- # same as:
- # test() (when command is char or length 1 string or symbol)
- # FileTest.command (others)
- # example:
- # sh[?e, "foo"]
- # sh[:e, "foo"]
- # sh["e", "foo"]
- # sh[:exists?, "foo"]
- # sh["exists?", "foo"]
+ # command: char or String or Symbol
+ # file1: String
+ # file2: String(optional)
+ # return: Boolean
+ # same as:
+ # test() (when command is char or length 1 string or symbol)
+ # FileTest.command (others)
+ # example:
+ # sh[?e, "foo"]
+ # sh[:e, "foo"]
+ # sh["e", "foo"]
+ # sh[:exists?, "foo"]
+ # sh["exists?", "foo"]
#
alias top_level_test test
def test(command, file1, file2=nil)
@@ -209,8 +209,8 @@ class Shell
#--
#
# CommandProcessor#mkdir(*path)
- # path: String
- # same as Dir.mkdir()
+ # path: String
+ # same as Dir.mkdir()
#
def mkdir(*path)
@shell.check_point
@@ -234,8 +234,8 @@ class Shell
#
# CommandProcessor#rmdir(*path)
- # path: String
- # same as Dir.rmdir()
+ # path: String
+ # same as Dir.rmdir()
#
def rmdir(*path)
@shell.check_point
@@ -249,13 +249,13 @@ class Shell
#
# CommandProcessor#system(command, *opts)
- # command: String
- # opts: String
- # return: SystemCommand
- # Same as system() function
- # example:
- # print sh.system("ls", "-l")
- # sh.system("ls", "-l") | sh.head > STDOUT
+ # command: String
+ # opts: String
+ # return: SystemCommand
+ # Same as system() function
+ # example:
+ # print sh.system("ls", "-l")
+ # sh.system("ls", "-l") | sh.head > STDOUT
#
def system(command, *opts)
if opts.empty?
@@ -270,7 +270,7 @@ class Shell
#
# ProcessCommand#rehash
- # clear command hash table.
+ # clear command hash table.
#
def rehash
@system_commands = {}
@@ -373,21 +373,21 @@ class Shell
#
# CommandProcessor.def_system_command(command, path)
- # command: String
- # path: String
- # define 'command()' method as method.
+ # command: String
+ # path: String
+ # define 'command()' method as method.
#
def self.def_system_command(command, path = command)
begin
eval((d = %Q[def #{command}(*opts)
- SystemCommand.new(@shell, '#{path}', *opts)
+ SystemCommand.new(@shell, '#{path}', *opts)
end]), nil, __FILE__, __LINE__ - 1)
rescue SyntaxError
Shell.notify "warn: Can't define #{command} path: #{path}."
end
Shell.notify "Define #{command} path: #{path}.", Shell.debug?
Shell.notify("Definition of #{command}: ", d,
- Shell.debug.kind_of?(Integer) && Shell.debug > 1)
+ Shell.debug.kind_of?(Integer) && Shell.debug > 1)
end
def self.undef_system_command(command)
@@ -417,11 +417,11 @@ class Shell
eval((d = %Q[def #{ali}(*opts)
@shell.__send__(:#{command},
*(CommandProcessor.alias_map[:#{ali}].call *opts))
- end]), nil, __FILE__, __LINE__ - 1)
+ end]), nil, __FILE__, __LINE__ - 1)
else
- args = opts.collect{|opt| '"' + opt + '"'}.join(",")
- eval((d = %Q[def #{ali}(*opts)
+ args = opts.collect{|opt| '"' + opt + '"'}.join(",")
+ eval((d = %Q[def #{ali}(*opts)
@shell.__send__(:#{command}, #{args}, *opts)
end]), nil, __FILE__, __LINE__ - 1)
end
@@ -432,7 +432,7 @@ class Shell
end
Shell.notify "Define #{ali} command: #{command}.", Shell.debug?
Shell.notify("Definition of #{ali}: ", d,
- Shell.debug.kind_of?(Integer) && Shell.debug > 1)
+ Shell.debug.kind_of?(Integer) && Shell.debug > 1)
self
end
@@ -444,14 +444,14 @@ class Shell
#
# CommandProcessor.def_builtin_commands(delegation_class, command_specs)
- # delegation_class: Class or Module
- # command_specs: [[command_name, [argument,...]],...]
- # command_name: String
- # arguments: String
- # FILENAME?? -> expand_path(filename??)
- # *FILENAME?? -> filename??.collect{|f|expand_path(f)}.join(", ")
- # define command_name(argument,...) as
- # delegation_class.command_name(argument,...)
+ # delegation_class: Class or Module
+ # command_specs: [[command_name, [argument,...]],...]
+ # command_name: String
+ # arguments: String
+ # FILENAME?? -> expand_path(filename??)
+ # *FILENAME?? -> filename??.collect{|f|expand_path(f)}.join(", ")
+ # define command_name(argument,...) as
+ # delegation_class.command_name(argument,...)
#
def self.def_builtin_commands(delegation_class, command_specs)
for meth, args in command_specs
@@ -469,18 +469,18 @@ class Shell
end
}.join(", ")
d = %Q[def #{meth}(#{arg_str})
- #{delegation_class}.#{meth}(#{call_arg_str})
- end]
- Shell.notify "Define #{meth}(#{arg_str})", Shell.debug?
- Shell.notify("Definition of #{meth}: ", d,
- Shell.debug.kind_of?(Integer) && Shell.debug > 1)
- eval d
+ #{delegation_class}.#{meth}(#{call_arg_str})
+ end]
+ Shell.notify "Define #{meth}(#{arg_str})", Shell.debug?
+ Shell.notify("Definition of #{meth}: ", d,
+ Shell.debug.kind_of?(Integer) && Shell.debug > 1)
+ eval d
end
end
#
# CommandProcessor.install_system_commands(pre)
- # pre: String - command name prefix
+ # pre: String - command name prefix
# defines every command which belongs in default_system_path via
# CommandProcessor.command(). It doesn't define already defined
# methods twice. By default, "pre_" is prefixes to each method
@@ -526,29 +526,29 @@ class Shell
end
Shell.notify "method added: Shell##{name}.", Shell.debug?
Shell.module_eval(%Q[def #{name}(*args, &block)
- begin
- @command_processor.__send__(:#{name}, *args, &block)
- rescue Exception
- $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
- $@.delete_if{|s| /^\\(eval\\):/ =~ s}
- raise
- end
+ begin
+ @command_processor.__send__(:#{name}, *args, &block)
+ rescue Exception
+ $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
+ $@.delete_if{|s| /^\\(eval\\):/ =~ s}
+ raise
+ end
end], __FILE__, __LINE__)
- if Shell::Filter.method_defined?(id)
- Shell.notify "warn: override definition of Shell::Filter##{name}."
- Shell.notify "warn: alias Shell##{name} to Shell::Filter##{name}_org."
- Filter.module_eval "alias #{name}_org #{name}"
- end
- Shell.notify "method added: Shell::Filter##{name}.", Shell.debug?
- Filter.module_eval(%Q[def #{name}(*args, &block)
- begin
- self | @shell.__send__(:#{name}, *args, &block)
- rescue Exception
- $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
- $@.delete_if{|s| /^\\(eval\\):/ =~ s}
- raise
- end
+ if Shell::Filter.method_defined?(id)
+ Shell.notify "warn: override definition of Shell::Filter##{name}."
+ Shell.notify "warn: alias Shell##{name} to Shell::Filter##{name}_org."
+ Filter.module_eval "alias #{name}_org #{name}"
+ end
+ Shell.notify "method added: Shell::Filter##{name}.", Shell.debug?
+ Filter.module_eval(%Q[def #{name}(*args, &block)
+ begin
+ self | @shell.__send__(:#{name}, *args, &block)
+ rescue Exception
+ $@.delete_if{|s| /:in `__getobj__'$/ =~ s} #`
+ $@.delete_if{|s| /^\\(eval\\):/ =~ s}
+ raise
+ end
end], __FILE__, __LINE__)
end
@@ -557,7 +557,7 @@ class Shell
#
def self.install_builtin_commands
# method related File.
- # (exclude open/foreach/unlink)
+ # (exclude open/foreach/unlink)
normal_delegation_file_methods = [
["atime", ["FILENAME"]],
["basename", ["fn", "*opts"]],
@@ -580,12 +580,12 @@ class Shell
["truncate", ["FILENAME", "length"]],
["utime", ["atime", "mtime", "*FILENAMES"]]]
- def_builtin_commands(File, normal_delegation_file_methods)
- alias_method :rm, :delete
+ def_builtin_commands(File, normal_delegation_file_methods)
+ alias_method :rm, :delete
- # method related FileTest
- def_builtin_commands(FileTest,
- FileTest.singleton_methods(false).collect{|m| [m, ["FILENAME"]]})
+ # method related FileTest
+ def_builtin_commands(FileTest,
+ FileTest.singleton_methods(false).collect{|m| [m, ["FILENAME"]]})
end
diff --git a/lib/shell/error.rb b/lib/shell/error.rb
index 8c37d2ab5e..2701338b5a 100644
--- a/lib/shell/error.rb
+++ b/lib/shell/error.rb
@@ -1,8 +1,8 @@
#
# shell/error.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.7 $
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
diff --git a/lib/shell/filter.rb b/lib/shell/filter.rb
index d07cc3dd07..df41b420ea 100644
--- a/lib/shell/filter.rb
+++ b/lib/shell/filter.rb
@@ -1,8 +1,8 @@
#
# shell/filter.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.7 $
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -19,8 +19,8 @@ class Shell
include Enumerable
def initialize(sh)
- @shell = sh # parent shell
- @input = nil # input filter
+ @shell = sh # parent shell
+ @input = nil # input filter
end
attr_reader :input
diff --git a/lib/shell/process-controller.rb b/lib/shell/process-controller.rb
index d50371fbbf..30f2229d39 100644
--- a/lib/shell/process-controller.rb
+++ b/lib/shell/process-controller.rb
@@ -1,8 +1,8 @@
#
# shell/process-controller.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.7 $
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -157,19 +157,19 @@ class Shell
@waiting_jobs.delete command
else
command = @waiting_jobs.shift
- # command.notify "job(%id) pre-start.", @shell.debug?
+# command.notify "job(%id) pre-start.", @shell.debug?
return unless command
end
@active_jobs.push command
command.start
- # command.notify "job(%id) post-start.", @shell.debug?
+# command.notify "job(%id) post-start.", @shell.debug?
# start all jobs that input from the job
for job in @waiting_jobs.dup
start_job(job) if job.input == command
end
- # command.notify "job(%id) post2-start.", @shell.debug?
+# command.notify "job(%id) post2-start.", @shell.debug?
end
end
@@ -254,20 +254,20 @@ class Shell
pid = fork {
Thread.list.each do |th|
- # th.kill unless [Thread.main, Thread.current].include?(th)
- th.kill unless Thread.current == th
+# th.kill unless [Thread.main, Thread.current].include?(th)
+ th.kill unless Thread.current == th
end
- STDIN.reopen(pipe_peer_in)
- STDOUT.reopen(pipe_peer_out)
+ STDIN.reopen(pipe_peer_in)
+ STDOUT.reopen(pipe_peer_out)
- ObjectSpace.each_object(IO) do |io|
- if ![STDIN, STDOUT, STDERR].include?(io)
- io.close unless io.closed?
+ ObjectSpace.each_object(IO) do |io|
+ if ![STDIN, STDOUT, STDERR].include?(io)
+ io.close unless io.closed?
+ end
end
- end
- yield
+ yield
}
end
pid_cv.signal
@@ -283,8 +283,8 @@ class Shell
rescue Errno::ECHILD
command.notify "warn: job(%id) was done already waitpid."
_pid = true
- # rescue
- # STDERR.puts $!
+ # rescue
+ # STDERR.puts $!
ensure
command.notify("Job(%id): Wait to finish when Process finished.", @shell.debug?)
# when the process ends, wait until the command terminates
@@ -296,11 +296,11 @@ class Shell
redo
end
- # command.notify "job(%id) pre-pre-finish.", @shell.debug?
+# command.notify "job(%id) pre-pre-finish.", @shell.debug?
@job_monitor.synchronize do
- # command.notify "job(%id) pre-finish.", @shell.debug?
+# command.notify "job(%id) pre-finish.", @shell.debug?
terminate_job(command)
- # command.notify "job(%id) pre-finish2.", @shell.debug?
+# command.notify "job(%id) pre-finish2.", @shell.debug?
@job_condition.signal
command.notify "job(%id) finish.", @shell.debug?
end
diff --git a/lib/shell/system-command.rb b/lib/shell/system-command.rb
index e97fab2549..50d994bb20 100644
--- a/lib/shell/system-command.rb
+++ b/lib/shell/system-command.rb
@@ -1,8 +1,8 @@
#
# shell/system-command.rb -
-# $Release Version: 0.7 $
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.7 $
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
@@ -141,9 +141,9 @@ class Shell
# ex)
# if you wish to output:
- # "shell: job(#{@command}:#{@pid}) close pipe-out."
- # then
- # mes: "job(%id) close pipe-out."
+ # "shell: job(#{@command}:#{@pid}) close pipe-out."
+ # then
+ # mes: "job(%id) close pipe-out."
# yorn: Boolean(@shell.debug? or @shell.verbose?)
def notify(*opts, &block)
@shell.notify(*opts) do |mes|
diff --git a/lib/shell/version.rb b/lib/shell/version.rb
index 946224c0cc..cbdb0e5e96 100644
--- a/lib/shell/version.rb
+++ b/lib/shell/version.rb
@@ -1,8 +1,8 @@
#
# version.rb - shell version definition file
-# $Release Version: 0.7$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+# $Release Version: 0.7$
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#
# --
#
diff --git a/lib/sync.rb b/lib/sync.rb
index 168ba9f5c8..bb2ad2b00f 100644
--- a/lib/sync.rb
+++ b/lib/sync.rb
@@ -1,8 +1,8 @@
#
# sync.rb - 2 phase lock with counter
-# $Release Version: 1.0$
-# $Revision$
-# by Keiju ISHITSUKA(keiju@ishitsuka.com)
+# $Release Version: 1.0$
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ishitsuka.com)
#
# --
# Sync_m, Synchronizer_m
@@ -10,8 +10,8 @@
# obj.extend(Sync_m)
# or
# class Foo
-# include Sync_m
-# :
+# include Sync_m
+# :
# end
#
# Sync_m#sync_mode
@@ -100,12 +100,12 @@ module Sync_m
def sync_extend
unless (defined? locked? and
- defined? shared? and
- defined? exclusive? and
- defined? lock and
- defined? unlock and
- defined? try_lock and
- defined? synchronize)
+ defined? shared? and
+ defined? exclusive? and
+ defined? lock and
+ defined? unlock and
+ defined? try_lock and
+ defined? synchronize)
Sync_m.define_aliases(singleton_class)
end
sync_initialize
@@ -281,7 +281,7 @@ module Sync_m
end
when EX
if sync_mode == UN or
- sync_mode == SH && sync_sh_locker.size == 1 && sync_sh_locker.include?(Thread.current)
+ sync_mode == SH && sync_sh_locker.size == 1 && sync_sh_locker.include?(Thread.current)
self.sync_mode = m
self.sync_ex_locker = Thread.current
self.sync_ex_count = 1
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 2b7c94f183..bf41195342 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -165,7 +165,7 @@ class Tempfile < DelegateClass(File)
__setobj__(@tmpfile)
end
- def _close # :nodoc:
+ def _close # :nodoc:
@tmpfile.close if @tmpfile
@tmpfile = nil
@data[1] = nil if @data
diff --git a/lib/thread.rb b/lib/thread.rb
index 9ae0ab0360..22dba2dd79 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -1,6 +1,6 @@
#
-# thread.rb - thread support classes
-# by Yukihiro Matsumoto <matz@netlab.co.jp>
+# thread.rb - thread support classes
+# by Yukihiro Matsumoto <matz@netlab.co.jp>
#
# Copyright (C) 2001 Yukihiro Matsumoto
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
@@ -144,7 +144,7 @@ class Queue
def initialize
@que = []
@waiting = []
- @que.taint # enable tainted comunication
+ @que.taint # enable tainted comunication
@waiting.taint
self.taint
@mutex = Mutex.new
@@ -252,7 +252,7 @@ class SizedQueue < Queue
raise ArgumentError, "queue size must be positive" unless max > 0
@max = max
@queue_wait = []
- @queue_wait.taint # enable tainted comunication
+ @queue_wait.taint # enable tainted comunication
super()
end
diff --git a/lib/thwait.rb b/lib/thwait.rb
index b099722ff6..b5574a1c28 100644
--- a/lib/thwait.rb
+++ b/lib/thwait.rb
@@ -1,8 +1,8 @@
#
# thwait.rb - thread synchronization class
-# $Release Version: 0.9 $
-# $Revision: 1.3 $
-# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd.)
+# $Release Version: 0.9 $
+# $Revision: 1.3 $
+# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd.)
require "thread.rb"
require "e2mmap.rb"
diff --git a/lib/un.rb b/lib/un.rb
index a1c3e26edd..0a2e37277a 100644
--- a/lib/un.rb
+++ b/lib/un.rb
@@ -69,9 +69,9 @@ end
#
# ruby -run -e cp -- [OPTION] SOURCE DEST
#
-# -p preserve file attributes if possible
-# -r copy recursively
-# -v verbose
+# -p preserve file attributes if possible
+# -r copy recursively
+# -v verbose
#
def cp
@@ -90,9 +90,9 @@ end
#
# ruby -run -e ln -- [OPTION] TARGET LINK_NAME
#
-# -s make symbolic links instead of hard links
-# -f remove existing destination files
-# -v verbose
+# -s make symbolic links instead of hard links
+# -f remove existing destination files
+# -v verbose
#
def ln
@@ -111,7 +111,7 @@ end
#
# ruby -run -e mv -- [OPTION] SOURCE DEST
#
-# -v verbose
+# -v verbose
#
def mv
@@ -127,9 +127,9 @@ end
#
# ruby -run -e rm -- [OPTION] FILE
#
-# -f ignore nonexistent files
-# -r remove the contents of directories recursively
-# -v verbose
+# -f ignore nonexistent files
+# -r remove the contents of directories recursively
+# -v verbose
#
def rm
@@ -146,8 +146,8 @@ end
#
# ruby -run -e mkdir -- [OPTION] DIR
#
-# -p no error if existing, make parent directories as needed
-# -v verbose
+# -p no error if existing, make parent directories as needed
+# -v verbose
#
def mkdir
@@ -163,8 +163,8 @@ end
#
# ruby -run -e rmdir -- [OPTION] DIR
#
-# -p remove DIRECTORY and its ancestors.
-# -v verbose
+# -p remove DIRECTORY and its ancestors.
+# -v verbose
#
def rmdir
@@ -179,10 +179,10 @@ end
#
# ruby -run -e install -- [OPTION] SOURCE DEST
#
-# -p apply access/modification times of SOURCE files to
-# corresponding destination files
-# -m set permission mode (as in chmod), instead of 0755
-# -v verbose
+# -p apply access/modification times of SOURCE files to
+# corresponding destination files
+# -m set permission mode (as in chmod), instead of 0755
+# -v verbose
#
def install
@@ -200,7 +200,7 @@ end
#
# ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
#
-# -v verbose
+# -v verbose
#
def chmod
@@ -215,7 +215,7 @@ end
#
# ruby -run -e touch -- [OPTION] FILE
#
-# -v verbose
+# -v verbose
#
def touch
@@ -229,9 +229,9 @@ end
#
# ruby -run -e wait_writable -- [OPTION] FILE
#
-# -n RETRY count to retry
-# -w SEC each wait time in seconds
-# -v verbose
+# -n RETRY count to retry
+# -w SEC each wait time in seconds
+# -v verbose
#
def wait_writable
@@ -260,15 +260,15 @@ end
#
# ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
#
-# -d ARGS run dir_config
-# -h ARGS run have_header
-# -l ARGS run have_library
-# -f ARGS run have_func
-# -v ARGS run have_var
-# -t ARGS run have_type
-# -m ARGS run have_macro
-# -c ARGS run have_const
-# --vendor install to vendor_ruby
+# -d ARGS run dir_config
+# -h ARGS run have_header
+# -l ARGS run have_library
+# -f ARGS run have_func
+# -v ARGS run have_var
+# -t ARGS run have_type
+# -m ARGS run have_macro
+# -c ARGS run have_const
+# --vendor install to vendor_ruby
#
def mkmf
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index 10f77caecb..aaafeba478 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -202,13 +202,13 @@ module URI
#
# == Usage
#
- # p = URI::Parser.new
- # p.parse("ldap://ldap.example.com/dc=example?user=john")
- # #=> #<URI::LDAP:0x00000000b9e7e8 URL:ldap://ldap.example.com/dc=example?user=john>
+ # p = URI::Parser.new
+ # p.parse("ldap://ldap.example.com/dc=example?user=john")
+ # #=> #<URI::LDAP:0x00000000b9e7e8 URL:ldap://ldap.example.com/dc=example?user=john>
#
def parse(uri)
scheme, userinfo, host, port,
- registry, path, opaque, query, fragment = self.split(uri)
+ registry, path, opaque, query, fragment = self.split(uri)
if scheme && URI.scheme_list.include?(scheme.upcase)
URI.scheme_list[scheme.upcase].new(scheme, userinfo, host, port,
@@ -273,7 +273,7 @@ module URI
# unless +schemes+ is provided. Then it is a Regexp.union with self.pattern[:X_ABS_URI]
def make_regexp(schemes = nil)
unless schemes
- @regexp[:ABS_URI_REF]
+ @regexp[:ABS_URI_REF]
else
/(?=#{Regexp.union(*schemes)}:)#{@pattern[:X_ABS_URI]}/x
end
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 78e3fc05f7..a37649545a 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -1321,8 +1321,8 @@ module URI
self.query, self.fragment, parser)
if rel.userinfo != oth.userinfo ||
- rel.host.to_s.downcase != oth.host.to_s.downcase ||
- rel.port != oth.port
+ rel.host.to_s.downcase != oth.host.to_s.downcase ||
+ rel.port != oth.port
if self.userinfo.nil? && self.host.nil?
return self, self.dup
diff --git a/lib/weakref.rb b/lib/weakref.rb
index 10ec5ad476..b3f3856db9 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -3,11 +3,11 @@
# Usage:
# foo = Object.new
# foo = Object.new
-# p foo.to_s # original's class
+# p foo.to_s # original's class
# foo = WeakRef.new(foo)
-# p foo.to_s # should be same class
+# p foo.to_s # should be same class
# ObjectSpace.garbage_collect
-# p foo.to_s # should raise exception (recycled)
+# p foo.to_s # should raise exception (recycled)
require "delegate"
require 'thread'
@@ -71,10 +71,10 @@ end
if __FILE__ == $0
# require 'thread'
foo = Object.new
- p foo.to_s # original's class
+ p foo.to_s # original's class
foo = WeakRef.new(foo)
- p foo.to_s # should be same class
+ p foo.to_s # should be same class
ObjectSpace.garbage_collect
ObjectSpace.garbage_collect
- p foo.to_s # should raise exception (recycled)
+ p foo.to_s # should raise exception (recycled)
end