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:
parent
cd5c309542
commit
85bae86cb6
14 changed files with 319 additions and 330 deletions
19
ChangeLog
19
ChangeLog
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
132
lib/matrix.rb
132
lib/matrix.rb
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,9 +7,7 @@ require 'yaml/encoding'
|
|||
require 'yaml/error'
|
||||
|
||||
module YAML
|
||||
|
||||
module BaseEmitter
|
||||
|
||||
def options( opt = nil )
|
||||
if opt
|
||||
@options[opt] || YAML::DEFAULTS[opt]
|
||||
|
@ -45,7 +43,6 @@ module YAML
|
|||
else
|
||||
'>'
|
||||
end
|
||||
|
||||
indt = $&.to_i if block =~ /\d+/
|
||||
if valx =~ /(\A\n*[ \t#]|^---\s+)/
|
||||
indt = options(:Indent) unless indt.to_i > 0
|
||||
|
@ -226,7 +223,6 @@ module YAML
|
|||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -243,5 +239,4 @@ module YAML
|
|||
push v
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue