1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/optparse/version.rb: remove variable shadowing to stop

warning.   [ruby-core:20612]

* lib/irb/completion.rb, lib/net/imap.rb, lib/prime.rb,
  lib/rinda/ring.rb, lib/racc/parser.rb,
  lib/shell/command-processor.rb, lib/yaml/yamlnode.rb: ditto.

* lib/racc/parser.rb: remove space before parentheses.

* lib/shell/command-processor.rb, lib/shell/process-controller.rb:
  use parentheses around arguments.

* lib/irb/ext/change-ws.rb, lib/rexml/validation/relaxng.rb,
  lib/yaml/baseemitter.rb: indentation fix.

* lib/matrix.rb: small cosmetic change.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-12-18 07:54:50 +00:00
parent cd5c309542
commit 85bae86cb6
14 changed files with 319 additions and 330 deletions

View file

@ -1,3 +1,22 @@
Thu Dec 18 16:48:12 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/optparse/version.rb: remove variable shadowing to stop
warning. [ruby-core:20612]
* lib/irb/completion.rb, lib/net/imap.rb, lib/prime.rb,
lib/rinda/ring.rb, lib/racc/parser.rb,
lib/shell/command-processor.rb, lib/yaml/yamlnode.rb: ditto.
* lib/racc/parser.rb: remove space before parentheses.
* lib/shell/command-processor.rb, lib/shell/process-controller.rb:
use parentheses around arguments.
* lib/irb/ext/change-ws.rb, lib/rexml/validation/relaxng.rb,
lib/yaml/baseemitter.rb: indentation fix.
* lib/matrix.rb: small cosmetic change.
Thu Dec 18 08:15:04 2008 James Edward Gray II <jeg2@ruby-lang.org>
* lib/xmlrpc/server.rb: Restricting method inspection to show only

View file

@ -159,7 +159,7 @@ module IRB
end
next if name != "IRB::Context" and
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
candidates.concat m.instance_methods(false).collect{|m| m.to_s}
candidates.concat m.instance_methods(false).collect{|x| x.to_s}
}
candidates.sort!
candidates.uniq!

View file

@ -56,6 +56,6 @@ module IRB
# end
# end
# alias change_workspace change_binding
end
end
end

View file

@ -140,10 +140,8 @@ class Matrix
#
#
def Matrix.columns(columns)
rows = (0 .. columns[0].size - 1).collect {
|i|
(0 .. columns.size - 1).collect {
|j|
rows = (0 .. columns[0].size - 1).collect {|i|
(0 .. columns.size - 1).collect {|j|
columns[j][i]
}
}
@ -159,8 +157,7 @@ class Matrix
#
def Matrix.diagonal(*values)
size = values.size
rows = (0 .. size - 1).collect {
|j|
rows = (0 .. size - 1).collect {|j|
row = Array.new(size).fill(0, 0, size)
row[j] = values[j]
row
@ -311,13 +308,11 @@ class Matrix
#
def column(j) # :yield: e
if block_given?
0.upto(row_size - 1) do
|i|
0.upto(row_size - 1) do |i|
yield @rows[i][j]
end
else
col = (0 .. row_size - 1).collect {
|i|
col = (0 .. row_size - 1).collect {|i|
@rows[i][j]
}
Vector.elements(col, false)
@ -364,8 +359,7 @@ class Matrix
Matrix.Raise ArgumentError, param.inspect
end
rows = @rows[from_row, size_row].collect{
|row|
rows = @rows[from_row, size_row].collect{|row|
row[from_col, size_col]
}
Matrix.rows(rows, false)
@ -421,8 +415,7 @@ class Matrix
def compare_by_row_vectors(rows, comparison = :==)
return false unless @rows.size == rows.size
0.upto(@rows.size - 1) do
|i|
0.upto(@rows.size - 1) do |i|
return false unless @rows[i].send(comparison, rows[i])
end
true
@ -462,10 +455,8 @@ class Matrix
def *(m) # m is matrix or vector or number
case(m)
when Numeric
rows = @rows.collect {
|row|
row.collect {
|e|
rows = @rows.collect {|row|
row.collect {|e|
e * m
}
}
@ -477,13 +468,10 @@ class Matrix
when Matrix
Matrix.Raise ErrDimensionMismatch if column_size != m.row_size
rows = (0 .. row_size - 1).collect {
|i|
(0 .. m.column_size - 1).collect {
|j|
rows = (0 .. row_size - 1).collect {|i|
(0 .. m.column_size - 1).collect {|j|
vij = 0
0.upto(column_size - 1) do
|k|
0.upto(column_size - 1) do |k|
vij += self[i, k] * m[k, j]
end
vij
@ -516,10 +504,8 @@ class Matrix
Matrix.Raise ErrDimensionMismatch unless row_size == m.row_size and column_size == m.column_size
rows = (0 .. row_size - 1).collect {
|i|
(0 .. column_size - 1).collect {
|j|
rows = (0 .. row_size - 1).collect {|i|
(0 .. column_size - 1).collect {|j|
self[i, j] + m[i, j]
}
}
@ -546,10 +532,8 @@ class Matrix
Matrix.Raise ErrDimensionMismatch unless row_size == m.row_size and column_size == m.column_size
rows = (0 .. row_size - 1).collect {
|i|
(0 .. column_size - 1).collect {
|j|
rows = (0 .. row_size - 1).collect {|i|
(0 .. column_size - 1).collect {|j|
self[i, j] - m[i, j]
}
}
@ -565,10 +549,8 @@ class Matrix
def /(other)
case other
when Numeric
rows = @rows.collect {
|row|
row.collect {
|e|
rows = @rows.collect {|row|
row.collect {|e|
e / other
}
}
@ -603,7 +585,7 @@ class Matrix
for k in 0..size
i = k
akk = a[k][k].abs
for j in (k+1)..size
((k+1)..size).each do |j|
v = a[j][k].abs
if v > akk
i = j
@ -697,12 +679,13 @@ class Matrix
det = 1
k = 0
begin
loop do
if (akk = a[k][k]) == 0
i = k
begin
return 0 if (i += 1) > size
end while a[i][k] == 0
loop do
return 0 if (ii += 1) > size
break unless a[i][k] == 0
end
a[i], a[k] = a[k], a[i]
akk = a[k][k]
det *= -1
@ -710,13 +693,13 @@ class Matrix
for i in k + 1 .. size
q = a[i][k].quo(akk)
(k + 1).upto(size) do
|j|
(k + 1).upto(size) do |j|
a[i][j] -= a[k][j] * q
end
end
det *= akk
end while (k += 1) <= size
break unless (k += 1) <= size
end
det
end
alias det determinant
@ -739,12 +722,13 @@ class Matrix
det = 1
k = 0
begin
loop do
if a[k][k].zero?
i = k
begin
loop do
return 0 if (i += 1) > size
end while a[i][k].zero?
break unless a[i][k].zero?
end
a[i], a[k] = a[k], a[i]
det *= -1
end
@ -761,7 +745,8 @@ class Matrix
end
end
det *= a[k][k]
end while (k += 1) <= size
break unless (k += 1) <= size
end
det
end
alias det_e determinant_e
@ -786,31 +771,32 @@ class Matrix
end
rank = 0
k = 0
begin
loop do
if (akk = a[k][k]) == 0
i = k
exists = true
begin
loop do
if (i += 1) > a_column_size - 1
exists = false
break
end
end while a[i][k] == 0
break unless a[i][k] == 0
end
if exists
a[i], a[k] = a[k], a[i]
akk = a[k][k]
else
i = k
exists = true
begin
loop do
if (i += 1) > a_row_size - 1
exists = false
break
end
end while a[k][i] == 0
break unless a[k][i] == 0
end
if exists
k.upto(a_column_size - 1) do
|j|
k.upto(a_column_size - 1) do |j|
a[j][k], a[j][i] = a[j][i], a[j][k]
end
akk = a[k][k]
@ -827,7 +813,8 @@ class Matrix
end
end
rank += 1
end while (k += 1) <= a_column_size - 1
break unless (k += 1) <= a_column_size - 1
end
return rank
end
@ -873,8 +860,7 @@ class Matrix
#
def trace
tr = 0
0.upto(column_size - 1) do
|i|
0.upto(column_size - 1) do |i|
tr += @rows[i][i]
end
tr
@ -916,8 +902,7 @@ class Matrix
# Returns an array of the row vectors of the matrix. See Vector.
#
def row_vectors
rows = (0 .. row_size - 1).collect {
|i|
rows = (0 .. row_size - 1).collect {|i|
row(i)
}
rows
@ -927,8 +912,7 @@ class Matrix
# Returns an array of the column vectors of the matrix. See Vector.
#
def column_vectors
columns = (0 .. column_size - 1).collect {
|i|
columns = (0 .. column_size - 1).collect {|i|
column(i)
}
columns
@ -961,8 +945,7 @@ class Matrix
# Overrides Object#to_s
#
def to_s
"Matrix[" + @rows.collect{
|row|
"Matrix[" + @rows.collect{|row|
"[" + row.collect{|e| e.to_s}.join(", ") + "]"
}.join(", ")+"]"
end
@ -1169,8 +1152,7 @@ class Vector
#
def each2(v) # :yield: e1, e2
Vector.Raise ErrDimensionMismatch if size != v.size
0.upto(size - 1) do
|i|
0.upto(size - 1) do |i|
yield @elements[i], v[i]
end
end
@ -1181,8 +1163,7 @@ class Vector
#
def collect2(v) # :yield: e1, e2
Vector.Raise ErrDimensionMismatch if size != v.size
(0 .. size - 1).collect do
|i|
(0 .. size - 1).collect do |i|
yield @elements[i], v[i]
end
end
@ -1253,8 +1234,7 @@ class Vector
case v
when Vector
Vector.Raise ErrDimensionMismatch if size != v.size
els = collect2(v) {
|v1, v2|
els = collect2(v) {|v1, v2|
v1 + v2
}
Vector.elements(els, false)
@ -1273,8 +1253,7 @@ class Vector
case v
when Vector
Vector.Raise ErrDimensionMismatch if size != v.size
els = collect2(v) {
|v1, v2|
els = collect2(v) {|v1, v2|
v1 - v2
}
Vector.elements(els, false)
@ -1298,8 +1277,7 @@ class Vector
Vector.Raise ErrDimensionMismatch if size != v.size
p = 0
each2(v) {
|v1, v2|
each2(v) {|v1, v2|
p += v1 * v2
}
p
@ -1309,8 +1287,7 @@ class Vector
# Like Array#collect.
#
def collect # :yield: e
els = @elements.collect {
|v|
els = @elements.collect {|v|
yield v
}
Vector.elements(els, false)
@ -1321,8 +1298,7 @@ class Vector
# Like Vector#collect2, but returns a Vector instead of an Array.
#
def map2(v) # :yield: e1, e2
els = collect2(v) {
|v1, v2|
els = collect2(v) {|v1, v2|
yield v1, v2
}
Vector.elements(els, false)

View file

@ -3216,7 +3216,7 @@ module Net
].join(':')
)
return response.keys.map { |k| qdval(k.to_s, response[k]) }.join(',')
return response.keys.map {|key| qdval(key.to_s, response[key]) }.join(',')
when STAGE_TWO
@stage = nil
# if at the second stage, return an empty string

View file

@ -1,7 +1,7 @@
# OptionParser internal utility
class << OptionParser
def show_version(*pkg)
def show_version(*pkgs)
progname = ARGV.options.program_name
result = false
show = proc do |klass, cname, version|
@ -19,14 +19,14 @@ class << OptionParser
puts str
result = true
end
if pkg.size == 1 and pkg[0] == "all"
if pkgs.size == 1 and pkgs[0] == "all"
self.search_const(::Object, /\AV(?:ERSION|ersion)\z/) do |klass, cname, version|
unless cname[1] == ?e and klass.const_defined?(:Version)
show.call(klass, cname.intern, version)
end
end
else
pkg.each do |pkg|
pkgs.each do |pkg|
begin
pkg = pkg.split(/::|\//).inject(::Object) {|m, c| m.const_get(c)}
v = case
@ -46,8 +46,8 @@ class << OptionParser
result
end
def each_const(path, klass = ::Object)
path.split(/::|\//).inject(klass) do |klass, name|
def each_const(path, base = ::Object)
path.split(/::|\//).inject(base) do |klass, name|
raise NameError, path unless Module === klass
klass.constants.grep(/#{name}/i) do |c|
klass.const_defined?(c) or next

View file

@ -411,8 +411,8 @@ class Prime
loop do
extend_table until @table.length > i
if !@table[i].zero?
(j...32).step(2) do |j|
return 32*i+j if !@table[i][j.div(2)].zero?
(j...32).step(2) do |k|
return 32*i+k if !@table[i][k.div(2)].zero?
end
end
i += 1; j = 1

View file

@ -159,7 +159,6 @@ module Racc
reduce_n, use_result, * = arg
_racc_init_sysvars
tok = nil
act = nil
i = nil
nerr = 0
@ -189,7 +188,7 @@ module Racc
;
end
while not (i = action_pointer[@racc_state[-1]]) or
while not(i = action_pointer[@racc_state[-1]]) or
not @racc_read_next or
@racc_t == 0 # $
unless i and i += @racc_t and

View file

@ -436,7 +436,7 @@ module REXML
arry[-1][-1].event_arg = evt[1]
@value = false
end
end
else
arry << [] if evt[0] == :start_element
arry[-1] << generate_event( evt )

View file

@ -256,15 +256,15 @@ if __FILE__ == $0
$stdin.gets
when 'w'
finger = Rinda::RingFinger.new(nil)
finger.lookup_ring do |ts|
p ts
ts.write([:hello, :world])
finger.lookup_ring do |ts2|
p ts2
ts2.write([:hello, :world])
end
when 'r'
finger = Rinda::RingFinger.new(nil)
finger.lookup_ring do |ts|
p ts
p ts.take([nil, nil])
finger.lookup_ring do |ts2|
p ts2
p ts2.take([nil, nil])
end
end
end

View file

@ -26,7 +26,7 @@ class Shell
#
m = [:initialize, :expand_path]
if Object.methods.first.kind_of?(String)
NoDelegateMethods = m.collect{|m| m.id2name}
NoDelegateMethods = m.collect{|x| x.id2name}
else
NoDelegateMethods = m
end
@ -124,7 +124,7 @@ class Shell
f = File.open(path, mode, perm)
File.chmod(perm & ~@shell.umask, path)
if block_given?
f.each &b
f.each(&b)
end
f
else

View file

@ -62,7 +62,7 @@ class Shell
end
def block_output_synchronize(&b)
@BlockOutputMonitor.synchronize &b
@BlockOutputMonitor.synchronize(&b)
end
def wait_to_finish_all_process_controllers

View file

@ -7,241 +7,236 @@ require 'yaml/encoding'
require 'yaml/error'
module YAML
module BaseEmitter
def options( opt = nil )
if opt
@options[opt] || YAML::DEFAULTS[opt]
else
@options
end
end
module BaseEmitter
def options( opt = nil )
if opt
@options[opt] || YAML::DEFAULTS[opt]
else
@options
end
end
def options=( opt )
@options = opt
end
#
# Emit binary data
#
def binary_base64( value )
self << "!binary "
self.node_text( [value].pack("m"), '|' )
end
#
# Emit plain, normal flowing text
#
def node_text( value, block = nil )
@seq_map = false
valx = value.dup
unless block
block =
if options(:UseBlock)
'|'
elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
'|'
else
'>'
end
indt = $&.to_i if block =~ /\d+/
if valx =~ /(\A\n*[ \t#]|^---\s+)/
indt = options(:Indent) unless indt.to_i > 0
block += indt.to_s
end
block +=
if valx =~ /\n\Z\n/
"+"
elsif valx =~ /\Z\n/
""
else
"-"
end
end
block += "\n"
if block[0] == ?"
esc_skip = ( "\t\n" unless valx =~ /^[ \t]/ ) || ""
valx = fold( YAML::escape( valx, esc_skip ) + "\"" ).chomp
self << '"' + indent_text( valx, indt, false )
else
if block[0] == ?>
valx = fold( valx )
end
#p [block, indt]
self << block + indent_text( valx, indt )
end
end
#
# Emit a simple, unqouted string
#
def simple( value )
@seq_map = false
self << value.to_s
end
#
# Emit double-quoted string
#
def double( value )
"\"#{YAML.escape( value )}\""
end
#
# Emit single-quoted string
#
def single( value )
"'#{value}'"
end
#
# Write a text block with the current indent
#
def indent_text( text, mod, first_line = true )
return "" if text.to_s.empty?
spacing = indent( mod )
text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line
return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" )
end
#
# Write a current indent
#
def indent( mod = nil )
#p [ self.id, level, mod, :INDENT ]
if level <= 0
mod ||= 0
else
mod ||= options(:Indent)
mod += ( level - 1 ) * options(:Indent)
end
return " " * mod
end
#
# Add indent to the buffer
#
def indent!
self << indent
end
#
# Folding paragraphs within a column
#
def fold( value )
value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do
$1 || $2 + ( $3 || "\n" )
end
end
#
# Quick mapping
#
def map( type, &e )
val = Mapping.new
e.call( val )
self << "#{type} " if type.length.nonzero?
#
# Empty hashes
#
if val.length.zero?
self << "{}"
@seq_map = false
else
# FIXME
# if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero?
# @headless = 1
# end
defkey = @options.delete( :DefaultKey )
if defkey
seq_map_shortcut
self << "= : "
defkey.to_yaml( :Emitter => self )
end
#
# Emit the key and value
#
val.each { |v|
seq_map_shortcut
if v[0].is_complex_yaml?
self << "? "
end
v[0].to_yaml( :Emitter => self )
if v[0].is_complex_yaml?
self << "\n"
indent!
end
self << ": "
v[1].to_yaml( :Emitter => self )
}
end
end
def seq_map_shortcut
# FIXME: seq_map needs to work with the new anchoring system
# if @seq_map
# @anchor_extras[@buffer.length - 1] = "\n" + indent
# @seq_map = false
# else
self << "\n"
indent!
# end
end
#
# Quick sequence
#
def seq( type, &e )
@seq_map = false
val = Sequence.new
e.call( val )
self << "#{type} " if type.length.nonzero?
#
# Empty arrays
#
if val.length.zero?
self << "[]"
else
# FIXME
# if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero?
# @headless = 1
# end
#
# Emit the key and value
#
val.each { |v|
self << "\n"
indent!
self << "- "
@seq_map = true if v.class == Hash
v.to_yaml( :Emitter => self )
}
end
end
def options=( opt )
@options = opt
end
#
# Emitter helper classes
# Emit binary data
#
class Mapping < Array
def add( k, v )
push [k, v]
end
def binary_base64( value )
self << "!binary "
self.node_text( [value].pack("m"), '|' )
end
class Sequence < Array
def add( v )
push v
#
# Emit plain, normal flowing text
#
def node_text( value, block = nil )
@seq_map = false
valx = value.dup
unless block
block =
if options(:UseBlock)
'|'
elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
'|'
else
'>'
end
indt = $&.to_i if block =~ /\d+/
if valx =~ /(\A\n*[ \t#]|^---\s+)/
indt = options(:Indent) unless indt.to_i > 0
block += indt.to_s
end
block +=
if valx =~ /\n\Z\n/
"+"
elsif valx =~ /\Z\n/
""
else
"-"
end
end
block += "\n"
if block[0] == ?"
esc_skip = ( "\t\n" unless valx =~ /^[ \t]/ ) || ""
valx = fold( YAML::escape( valx, esc_skip ) + "\"" ).chomp
self << '"' + indent_text( valx, indt, false )
else
if block[0] == ?>
valx = fold( valx )
end
#p [block, indt]
self << block + indent_text( valx, indt )
end
end
#
# Emit a simple, unqouted string
#
def simple( value )
@seq_map = false
self << value.to_s
end
#
# Emit double-quoted string
#
def double( value )
"\"#{YAML.escape( value )}\""
end
#
# Emit single-quoted string
#
def single( value )
"'#{value}'"
end
#
# Write a text block with the current indent
#
def indent_text( text, mod, first_line = true )
return "" if text.to_s.empty?
spacing = indent( mod )
text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line
return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" )
end
#
# Write a current indent
#
def indent( mod = nil )
#p [ self.id, level, mod, :INDENT ]
if level <= 0
mod ||= 0
else
mod ||= options(:Indent)
mod += ( level - 1 ) * options(:Indent)
end
return " " * mod
end
#
# Add indent to the buffer
#
def indent!
self << indent
end
#
# Folding paragraphs within a column
#
def fold( value )
value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do
$1 || $2 + ( $3 || "\n" )
end
end
#
# Quick mapping
#
def map( type, &e )
val = Mapping.new
e.call( val )
self << "#{type} " if type.length.nonzero?
#
# Empty hashes
#
if val.length.zero?
self << "{}"
@seq_map = false
else
# FIXME
# if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero?
# @headless = 1
# end
defkey = @options.delete( :DefaultKey )
if defkey
seq_map_shortcut
self << "= : "
defkey.to_yaml( :Emitter => self )
end
#
# Emit the key and value
#
val.each { |v|
seq_map_shortcut
if v[0].is_complex_yaml?
self << "? "
end
v[0].to_yaml( :Emitter => self )
if v[0].is_complex_yaml?
self << "\n"
indent!
end
self << ": "
v[1].to_yaml( :Emitter => self )
}
end
end
def seq_map_shortcut
# FIXME: seq_map needs to work with the new anchoring system
# if @seq_map
# @anchor_extras[@buffer.length - 1] = "\n" + indent
# @seq_map = false
# else
self << "\n"
indent!
# end
end
#
# Quick sequence
#
def seq( type, &e )
@seq_map = false
val = Sequence.new
e.call( val )
self << "#{type} " if type.length.nonzero?
#
# Empty arrays
#
if val.length.zero?
self << "[]"
else
# FIXME
# if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero?
# @headless = 1
# end
#
# Emit the key and value
#
val.each { |v|
self << "\n"
indent!
self << "- "
@seq_map = true if v.class == Hash
v.to_yaml( :Emitter => self )
}
end
end
end
#
# Emitter helper classes
#
class Mapping < Array
def add( k, v )
push [k, v]
end
end
class Sequence < Array
def add( v )
push v
end
end
end

View file

@ -11,13 +11,13 @@ module YAML
class YamlNode
include BaseNode
attr_accessor :kind, :type_id, :value, :anchor
def initialize( t, v )
def initialize(t, v)
@type_id = t
if Hash === v
@kind = 'map'
@value = {}
v.each { |k,v|
@value[ k.transform ] = [ k, v ]
v.each {|key,val|
@value[key.transform] = [key, val]
}
elsif Array === v
@kind = 'seq'