mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib: Convert tabs to spaces for ruby files per
http://redmine.ruby-lang.org/projects/ruby/wiki/DeveloperHowto#coding-style Patch by Steve Klabnik [Ruby 1.9 - Bug #4730] Patch by Jason Dew [Ruby 1.9 - Feature #4718] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
34276148c4
commit
7bbf2f3085
67 changed files with 3823 additions and 3814 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Thu May 19 06:16:41 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib: Convert tabs to spaces for ruby files per
|
||||||
|
http://redmine.ruby-lang.org/projects/ruby/wiki/DeveloperHowto#coding-style
|
||||||
|
Patch by Steve Klabnik [Ruby 1.9 - Bug #4730]
|
||||||
|
Patch by Jason Dew [Ruby 1.9 - Feature #4718]
|
||||||
|
|
||||||
Thu May 19 06:06:07 2011 Eric Hodel <drbrain@segment7.net>
|
Thu May 19 06:06:07 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* lib/cgi/util.rb: Improve documentation. Patch by Clinton Nixon.
|
* lib/cgi/util.rb: Improve documentation. Patch by Clinton Nixon.
|
||||||
|
|
|
@ -548,9 +548,9 @@ if __FILE__ == $0
|
||||||
x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure
|
x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure
|
||||||
x.report("times:") {n.times do ; _ = "1"; end}
|
x.report("times:") {n.times do ; _ = "1"; end}
|
||||||
x.report("upto:") {1.upto(n) do ; _ = "1"; end}
|
x.report("upto:") {1.upto(n) do ; _ = "1"; end}
|
||||||
end
|
end
|
||||||
|
|
||||||
benchmark do
|
benchmark do
|
||||||
[
|
[
|
||||||
measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure
|
measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure
|
||||||
measure{n.times do ; _ = "1"; end},
|
measure{n.times do ; _ = "1"; end},
|
||||||
|
|
|
@ -21,9 +21,9 @@ end
|
||||||
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
|
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
|
||||||
|
|
||||||
class DEBUGGER__
|
class DEBUGGER__
|
||||||
MUTEX = Mutex.new
|
MUTEX = Mutex.new
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
DEBUG_LAST_CMD = []
|
DEBUG_LAST_CMD = []
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -548,7 +548,7 @@ Commands
|
||||||
p expression evaluate expression and print its value
|
p expression evaluate expression and print its value
|
||||||
h[elp] print this help
|
h[elp] print this help
|
||||||
<everything else> evaluate
|
<everything else> evaluate
|
||||||
EOHELP
|
EOHELP
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_expressions(binding)
|
def display_expressions(binding)
|
||||||
|
|
|
@ -72,7 +72,7 @@ module IRB
|
||||||
ensure
|
ensure
|
||||||
irb_at_exit
|
irb_at_exit
|
||||||
end
|
end
|
||||||
# print "\n"
|
# print "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def IRB.irb_at_exit
|
def IRB.irb_at_exit
|
||||||
|
|
|
@ -478,7 +478,7 @@ class Logger
|
||||||
@logdev.close if @logdev
|
@logdev.close if @logdev
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Severity label for logging. (max 5 char)
|
# Severity label for logging. (max 5 char)
|
||||||
SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)
|
SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)
|
||||||
|
|
38
lib/mkmf.rb
38
lib/mkmf.rb
|
@ -337,12 +337,12 @@ def log_src(src)
|
||||||
Logging::message <<"EOM"
|
Logging::message <<"EOM"
|
||||||
checked program was:
|
checked program was:
|
||||||
/* begin */
|
/* begin */
|
||||||
EOM
|
EOM
|
||||||
src.each_with_index {|line, no| Logging::message fmt, no+1, line}
|
src.each_with_index {|line, no| Logging::message fmt, no+1, line}
|
||||||
Logging::message <<"EOM"
|
Logging::message <<"EOM"
|
||||||
/* end */
|
/* end */
|
||||||
|
|
||||||
EOM
|
EOM
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_tmpsrc(src)
|
def create_tmpsrc(src)
|
||||||
|
@ -547,7 +547,7 @@ end
|
||||||
def try_static_assert(expr, headers = nil, opt = "", &b)
|
def try_static_assert(expr, headers = nil, opt = "", &b)
|
||||||
headers = cpp_include(headers)
|
headers = cpp_include(headers)
|
||||||
try_compile(<<SRC, opt, &b)
|
try_compile(<<SRC, opt, &b)
|
||||||
#{headers}
|
#{headers}
|
||||||
/*top*/
|
/*top*/
|
||||||
int conftest_const[(#{expr}) ? 1 : -1];
|
int conftest_const[(#{expr}) ? 1 : -1];
|
||||||
SRC
|
SRC
|
||||||
|
@ -616,15 +616,15 @@ def try_func(func, libs, headers = nil, &b)
|
||||||
decltype = proc {|x| "void ((*#{x})())"}
|
decltype = proc {|x| "void ((*#{x})())"}
|
||||||
end
|
end
|
||||||
try_link(<<"SRC", libs, &b) or
|
try_link(<<"SRC", libs, &b) or
|
||||||
#{headers}
|
#{headers}
|
||||||
/*top*/
|
/*top*/
|
||||||
#{MAIN_DOES_NOTHING}
|
#{MAIN_DOES_NOTHING}
|
||||||
int t() { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return 0; }
|
int t() { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return 0; }
|
||||||
SRC
|
SRC
|
||||||
call && try_link(<<"SRC", libs, &b)
|
call && try_link(<<"SRC", libs, &b)
|
||||||
#{headers}
|
#{headers}
|
||||||
/*top*/
|
/*top*/
|
||||||
#{MAIN_DOES_NOTHING}
|
#{MAIN_DOES_NOTHING}
|
||||||
int t() { #{func}(); return 0; }
|
int t() { #{func}(); return 0; }
|
||||||
SRC
|
SRC
|
||||||
end
|
end
|
||||||
|
@ -633,9 +633,9 @@ end
|
||||||
def try_var(var, headers = nil, &b)
|
def try_var(var, headers = nil, &b)
|
||||||
headers = cpp_include(headers)
|
headers = cpp_include(headers)
|
||||||
try_compile(<<"SRC", &b)
|
try_compile(<<"SRC", &b)
|
||||||
#{headers}
|
#{headers}
|
||||||
/*top*/
|
/*top*/
|
||||||
#{MAIN_DOES_NOTHING}
|
#{MAIN_DOES_NOTHING}
|
||||||
int t() { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
|
int t() { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
|
||||||
SRC
|
SRC
|
||||||
end
|
end
|
||||||
|
@ -999,9 +999,9 @@ end
|
||||||
def have_struct_member(type, member, headers = nil, &b)
|
def have_struct_member(type, member, headers = nil, &b)
|
||||||
checking_for checking_message("#{type}.#{member}", headers) do
|
checking_for checking_message("#{type}.#{member}", headers) do
|
||||||
if try_compile(<<"SRC", &b)
|
if try_compile(<<"SRC", &b)
|
||||||
#{cpp_include(headers)}
|
#{cpp_include(headers)}
|
||||||
/*top*/
|
/*top*/
|
||||||
#{MAIN_DOES_NOTHING}
|
#{MAIN_DOES_NOTHING}
|
||||||
int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
|
int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
|
||||||
SRC
|
SRC
|
||||||
$defs.push(format("-DHAVE_%s_%s", type.tr_cpp, member.tr_cpp))
|
$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)
|
def try_type(type, headers = nil, opt = "", &b)
|
||||||
if try_compile(<<"SRC", opt, &b)
|
if try_compile(<<"SRC", opt, &b)
|
||||||
#{cpp_include(headers)}
|
#{cpp_include(headers)}
|
||||||
/*top*/
|
/*top*/
|
||||||
typedef #{type} conftest_type;
|
typedef #{type} conftest_type;
|
||||||
int conftestval[sizeof(conftest_type)?1:-1];
|
int conftestval[sizeof(conftest_type)?1:-1];
|
||||||
|
@ -1077,7 +1077,7 @@ end
|
||||||
def try_const(const, headers = nil, opt = "", &b)
|
def try_const(const, headers = nil, opt = "", &b)
|
||||||
const, type = *const
|
const, type = *const
|
||||||
if try_compile(<<"SRC", opt, &b)
|
if try_compile(<<"SRC", opt, &b)
|
||||||
#{cpp_include(headers)}
|
#{cpp_include(headers)}
|
||||||
/*top*/
|
/*top*/
|
||||||
typedef #{type || 'int'} conftest_type;
|
typedef #{type || 'int'} conftest_type;
|
||||||
conftest_type conftestval = #{type ? '' : '(int)'}#{const};
|
conftest_type conftestval = #{type ? '' : '(int)'}#{const};
|
||||||
|
@ -1239,10 +1239,10 @@ end
|
||||||
# pointer.
|
# pointer.
|
||||||
def scalar_ptr_type?(type, member = nil, headers = nil, &b)
|
def scalar_ptr_type?(type, member = nil, headers = nil, &b)
|
||||||
try_compile(<<"SRC", &b) # pointer
|
try_compile(<<"SRC", &b) # pointer
|
||||||
#{cpp_include(headers)}
|
#{cpp_include(headers)}
|
||||||
/*top*/
|
/*top*/
|
||||||
volatile #{type} conftestval;
|
volatile #{type} conftestval;
|
||||||
#{MAIN_DOES_NOTHING}
|
#{MAIN_DOES_NOTHING}
|
||||||
int t() {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));}
|
int t() {return (int)(1-*(conftestval#{member ? ".#{member}" : ""}));}
|
||||||
SRC
|
SRC
|
||||||
end
|
end
|
||||||
|
@ -1251,10 +1251,10 @@ end
|
||||||
# pointer.
|
# pointer.
|
||||||
def scalar_type?(type, member = nil, headers = nil, &b)
|
def scalar_type?(type, member = nil, headers = nil, &b)
|
||||||
try_compile(<<"SRC", &b) # pointer
|
try_compile(<<"SRC", &b) # pointer
|
||||||
#{cpp_include(headers)}
|
#{cpp_include(headers)}
|
||||||
/*top*/
|
/*top*/
|
||||||
volatile #{type} conftestval;
|
volatile #{type} conftestval;
|
||||||
#{MAIN_DOES_NOTHING}
|
#{MAIN_DOES_NOTHING}
|
||||||
int t() {return (int)(1-(conftestval#{member ? ".#{member}" : ""}));}
|
int t() {return (int)(1-(conftestval#{member ? ".#{member}" : ""}));}
|
||||||
SRC
|
SRC
|
||||||
end
|
end
|
||||||
|
@ -1266,7 +1266,7 @@ def have_typeof?
|
||||||
$typeof = %w[__typeof__ typeof].find do |t|
|
$typeof = %w[__typeof__ typeof].find do |t|
|
||||||
try_compile(<<SRC)
|
try_compile(<<SRC)
|
||||||
int rbcv_foo;
|
int rbcv_foo;
|
||||||
#{t}(rbcv_foo) rbcv_bar;
|
#{t}(rbcv_foo) rbcv_bar;
|
||||||
SRC
|
SRC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1644,7 +1644,7 @@ ECHO1 = $(V:1=@:)
|
||||||
ECHO = $(ECHO1:0=@echo)
|
ECHO = $(ECHO1:0=@echo)
|
||||||
|
|
||||||
#### Start of system configuration section. ####
|
#### 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}
|
srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {mkintpath(CONFIG[$1||$2])}.quote}
|
||||||
topdir = #{mkintpath($extmk ? CONFIG["topdir"] : $topdir).quote}
|
topdir = #{mkintpath($extmk ? CONFIG["topdir"] : $topdir).quote}
|
||||||
hdrdir = #{mkintpath(CONFIG["hdrdir"]).quote}
|
hdrdir = #{mkintpath(CONFIG["hdrdir"]).quote}
|
||||||
|
|
134
lib/net/imap.rb
134
lib/net/imap.rb
|
@ -2032,41 +2032,41 @@ module Net
|
||||||
T_TEXT = :TEXT
|
T_TEXT = :TEXT
|
||||||
|
|
||||||
BEG_REGEXP = /\G(?:\
|
BEG_REGEXP = /\G(?:\
|
||||||
(?# 1: SPACE )( +)|\
|
(?# 1: SPACE )( +)|\
|
||||||
(?# 2: NIL )(NIL)(?=[\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+])|\
|
(?# 2: NIL )(NIL)(?=[\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+])|\
|
||||||
(?# 3: NUMBER )(\d+)(?=[\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+])|\
|
(?# 3: NUMBER )(\d+)(?=[\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+])|\
|
||||||
(?# 4: ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+]+)|\
|
(?# 4: ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*#{'"'}\\\[\]+]+)|\
|
||||||
(?# 5: QUOTED )"((?:[^\x00\r\n"\\]|\\["\\])*)"|\
|
(?# 5: QUOTED )"((?:[^\x00\r\n"\\]|\\["\\])*)"|\
|
||||||
(?# 6: LPAR )(\()|\
|
(?# 6: LPAR )(\()|\
|
||||||
(?# 7: RPAR )(\))|\
|
(?# 7: RPAR )(\))|\
|
||||||
(?# 8: BSLASH )(\\)|\
|
(?# 8: BSLASH )(\\)|\
|
||||||
(?# 9: STAR )(\*)|\
|
(?# 9: STAR )(\*)|\
|
||||||
(?# 10: LBRA )(\[)|\
|
(?# 10: LBRA )(\[)|\
|
||||||
(?# 11: RBRA )(\])|\
|
(?# 11: RBRA )(\])|\
|
||||||
(?# 12: LITERAL )\{(\d+)\}\r\n|\
|
(?# 12: LITERAL )\{(\d+)\}\r\n|\
|
||||||
(?# 13: PLUS )(\+)|\
|
(?# 13: PLUS )(\+)|\
|
||||||
(?# 14: PERCENT )(%)|\
|
(?# 14: PERCENT )(%)|\
|
||||||
(?# 15: CRLF )(\r\n)|\
|
(?# 15: CRLF )(\r\n)|\
|
||||||
(?# 16: EOF )(\z))/ni
|
(?# 16: EOF )(\z))/ni
|
||||||
|
|
||||||
DATA_REGEXP = /\G(?:\
|
DATA_REGEXP = /\G(?:\
|
||||||
(?# 1: SPACE )( )|\
|
(?# 1: SPACE )( )|\
|
||||||
(?# 2: NIL )(NIL)|\
|
(?# 2: NIL )(NIL)|\
|
||||||
(?# 3: NUMBER )(\d+)|\
|
(?# 3: NUMBER )(\d+)|\
|
||||||
(?# 4: QUOTED )"((?:[^\x00\r\n"\\]|\\["\\])*)"|\
|
(?# 4: QUOTED )"((?:[^\x00\r\n"\\]|\\["\\])*)"|\
|
||||||
(?# 5: LITERAL )\{(\d+)\}\r\n|\
|
(?# 5: LITERAL )\{(\d+)\}\r\n|\
|
||||||
(?# 6: LPAR )(\()|\
|
(?# 6: LPAR )(\()|\
|
||||||
(?# 7: RPAR )(\)))/ni
|
(?# 7: RPAR )(\)))/ni
|
||||||
|
|
||||||
TEXT_REGEXP = /\G(?:\
|
TEXT_REGEXP = /\G(?:\
|
||||||
(?# 1: TEXT )([^\x00\r\n]*))/ni
|
(?# 1: TEXT )([^\x00\r\n]*))/ni
|
||||||
|
|
||||||
RTEXT_REGEXP = /\G(?:\
|
RTEXT_REGEXP = /\G(?:\
|
||||||
(?# 1: LBRA )(\[)|\
|
(?# 1: LBRA )(\[)|\
|
||||||
(?# 2: TEXT )([^\x00\r\n]*))/ni
|
(?# 2: TEXT )([^\x00\r\n]*))/ni
|
||||||
|
|
||||||
CTEXT_REGEXP = /\G(?:\
|
CTEXT_REGEXP = /\G(?:\
|
||||||
(?# 1: TEXT )([^\x00\r\n\]]*))/ni
|
(?# 1: TEXT )([^\x00\r\n\]]*))/ni
|
||||||
|
|
||||||
Token = Struct.new(:symbol, :value)
|
Token = Struct.new(:symbol, :value)
|
||||||
|
|
||||||
|
@ -2932,11 +2932,11 @@ module Net
|
||||||
end
|
end
|
||||||
|
|
||||||
ADDRESS_REGEXP = /\G\
|
ADDRESS_REGEXP = /\G\
|
||||||
(?# 1: NAME )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
|
(?# 1: NAME )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
|
||||||
(?# 2: ROUTE )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
|
(?# 2: ROUTE )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
|
||||||
(?# 3: MAILBOX )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
|
(?# 3: MAILBOX )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)") \
|
||||||
(?# 4: HOST )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)")\
|
(?# 4: HOST )(?:NIL|"((?:[^\x80-\xff\x00\r\n"\\]|\\["\\])*)")\
|
||||||
\)/ni
|
\)/ni
|
||||||
|
|
||||||
def address
|
def address
|
||||||
match(T_LPAR)
|
match(T_LPAR)
|
||||||
|
@ -2965,42 +2965,42 @@ module Net
|
||||||
return Address.new(name, route, mailbox, host)
|
return Address.new(name, route, mailbox, host)
|
||||||
end
|
end
|
||||||
|
|
||||||
# def flag_list
|
# def flag_list
|
||||||
# result = []
|
# result = []
|
||||||
# match(T_LPAR)
|
# match(T_LPAR)
|
||||||
# while true
|
# while true
|
||||||
# token = lookahead
|
# token = lookahead
|
||||||
# case token.symbol
|
# case token.symbol
|
||||||
# when T_RPAR
|
# when T_RPAR
|
||||||
# shift_token
|
# shift_token
|
||||||
# break
|
# break
|
||||||
# when T_SPACE
|
# when T_SPACE
|
||||||
# shift_token
|
# shift_token
|
||||||
# end
|
# end
|
||||||
# result.push(flag)
|
# result.push(flag)
|
||||||
# end
|
# end
|
||||||
# return result
|
# return result
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# def flag
|
# def flag
|
||||||
# token = lookahead
|
# token = lookahead
|
||||||
# if token.symbol == T_BSLASH
|
# if token.symbol == T_BSLASH
|
||||||
# shift_token
|
# shift_token
|
||||||
# token = lookahead
|
# token = lookahead
|
||||||
# if token.symbol == T_STAR
|
# if token.symbol == T_STAR
|
||||||
# shift_token
|
# shift_token
|
||||||
# return token.value.intern
|
# return token.value.intern
|
||||||
# else
|
# else
|
||||||
# return atom.intern
|
# return atom.intern
|
||||||
# end
|
# end
|
||||||
# else
|
# else
|
||||||
# return atom
|
# return atom
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
FLAG_REGEXP = /\
|
FLAG_REGEXP = /\
|
||||||
(?# FLAG )\\([^\x80-\xff(){ \x00-\x1f\x7f%"\\]+)|\
|
(?# FLAG )\\([^\x80-\xff(){ \x00-\x1f\x7f%"\\]+)|\
|
||||||
(?# ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*"\\]+)/n
|
(?# ATOM )([^\x80-\xff(){ \x00-\x1f\x7f%*"\\]+)/n
|
||||||
|
|
||||||
def flag_list
|
def flag_list
|
||||||
if @str.index(/\(([^)]*)\)/ni, @pos)
|
if @str.index(/\(([^)]*)\)/ni, @pos)
|
||||||
|
@ -3514,7 +3514,7 @@ usage: #{$0} [options] <host>
|
||||||
--auth=AUTH specifies auth type
|
--auth=AUTH specifies auth type
|
||||||
--starttls use starttls
|
--starttls use starttls
|
||||||
--ssl use ssl
|
--ssl use ssl
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -3649,7 +3649,7 @@ summary display summary
|
||||||
fetch [msgno] display message
|
fetch [msgno] display message
|
||||||
logout logout
|
logout logout
|
||||||
help, ? display help message
|
help, ? display help message
|
||||||
EOF
|
EOF
|
||||||
else
|
else
|
||||||
print "unknown command: ", cmd, "\n"
|
print "unknown command: ", cmd, "\n"
|
||||||
end
|
end
|
||||||
|
|
|
@ -760,5 +760,5 @@ module Net
|
||||||
end
|
end
|
||||||
|
|
||||||
end # class Telnet
|
end # class Telnet
|
||||||
end # module Net
|
end # module Net
|
||||||
|
|
||||||
|
|
216
lib/prime.rb
216
lib/prime.rb
|
@ -100,50 +100,50 @@ class Prime
|
||||||
def method_added(method) # :nodoc:
|
def method_added(method) # :nodoc:
|
||||||
(class<< self;self;end).def_delegator :instance, method
|
(class<< self;self;end).def_delegator :instance, method
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Iterates the given block over all prime numbers.
|
# Iterates the given block over all prime numbers.
|
||||||
#
|
#
|
||||||
# == Parameters
|
# == Parameters
|
||||||
# +ubound+::
|
# +ubound+::
|
||||||
# Optional. An arbitrary positive number.
|
# Optional. An arbitrary positive number.
|
||||||
# The upper bound of enumeration. The method enumerates
|
# The upper bound of enumeration. The method enumerates
|
||||||
# prime numbers infinitely if +ubound+ is nil.
|
# prime numbers infinitely if +ubound+ is nil.
|
||||||
# +generator+::
|
# +generator+::
|
||||||
# Optional. An implementation of pseudo-prime generator.
|
# Optional. An implementation of pseudo-prime generator.
|
||||||
#
|
#
|
||||||
# == Return value
|
# == Return value
|
||||||
# An evaluated value of the given block at the last time.
|
# An evaluated value of the given block at the last time.
|
||||||
# Or an enumerator which is compatible to an +Enumerator+
|
# Or an enumerator which is compatible to an +Enumerator+
|
||||||
# if no block given.
|
# if no block given.
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
# Calls +block+ once for each prime number, passing the prime as
|
# Calls +block+ once for each prime number, passing the prime as
|
||||||
# a parameter.
|
# a parameter.
|
||||||
#
|
#
|
||||||
# +ubound+::
|
# +ubound+::
|
||||||
# Upper bound of prime numbers. The iterator stops after
|
# Upper bound of prime numbers. The iterator stops after
|
||||||
# yields all prime numbers p <= +ubound+.
|
# yields all prime numbers p <= +ubound+.
|
||||||
#
|
#
|
||||||
# == Note
|
# == Note
|
||||||
# +Prime+.+new+ returns a object extended by +Prime+::+OldCompatibility+
|
# +Prime+.+new+ returns a object extended by +Prime+::+OldCompatibility+
|
||||||
# in order to compatibility to Ruby 1.8, and +Prime+#each is overwritten
|
# in order to compatibility to Ruby 1.8, and +Prime+#each is overwritten
|
||||||
# by +Prime+::+OldCompatibility+#+each+.
|
# by +Prime+::+OldCompatibility+#+each+.
|
||||||
#
|
#
|
||||||
# +Prime+.+new+ is now obsolete. Use +Prime+.+instance+.+each+ or simply
|
# +Prime+.+new+ is now obsolete. Use +Prime+.+instance+.+each+ or simply
|
||||||
# +Prime+.+each+.
|
# +Prime+.+each+.
|
||||||
def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
|
def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
|
||||||
generator.upper_bound = ubound
|
generator.upper_bound = ubound
|
||||||
generator.each(&block)
|
generator.each(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Returns true if +value+ is prime, false for a composite.
|
# Returns true if +value+ is prime, false for a composite.
|
||||||
#
|
#
|
||||||
# == Parameters
|
# == Parameters
|
||||||
# +value+:: an arbitrary integer to be checked.
|
# +value+:: an arbitrary integer to be checked.
|
||||||
# +generator+:: optional. A pseudo-prime generator.
|
# +generator+:: optional. A pseudo-prime generator.
|
||||||
def prime?(value, generator = Prime::Generator23.new)
|
def prime?(value, generator = Prime::Generator23.new)
|
||||||
value = -value if value < 0
|
value = -value if value < 0
|
||||||
return false if value < 2
|
return false if value < 2
|
||||||
for num in generator
|
for num in generator
|
||||||
|
@ -151,48 +151,48 @@ class Prime
|
||||||
return true if q < num
|
return true if q < num
|
||||||
return false if r == 0
|
return false if r == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Re-composes a prime factorization and returns the product.
|
# Re-composes a prime factorization and returns the product.
|
||||||
#
|
#
|
||||||
# == Parameters
|
# == Parameters
|
||||||
# +pd+:: Array of pairs of integers. The each internal
|
# +pd+:: Array of pairs of integers. The each internal
|
||||||
# pair consists of a prime number -- a prime factor --
|
# pair consists of a prime number -- a prime factor --
|
||||||
# and a natural number -- an exponent.
|
# and a natural number -- an exponent.
|
||||||
#
|
#
|
||||||
# == Example
|
# == Example
|
||||||
# For [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]], it returns
|
# 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.
|
# p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
|
||||||
#
|
#
|
||||||
# Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
|
# Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
|
||||||
def int_from_prime_division(pd)
|
def int_from_prime_division(pd)
|
||||||
pd.inject(1){|value, (prime, index)|
|
pd.inject(1){|value, (prime, index)|
|
||||||
value *= prime**index
|
value *= prime**index
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the factorization of +value+.
|
# Returns the factorization of +value+.
|
||||||
#
|
#
|
||||||
# == Parameters
|
# == Parameters
|
||||||
# +value+:: An arbitrary integer.
|
# +value+:: An arbitrary integer.
|
||||||
# +generator+:: Optional. A pseudo-prime generator.
|
# +generator+:: Optional. A pseudo-prime generator.
|
||||||
# +generator+.succ must return the next
|
# +generator+.succ must return the next
|
||||||
# pseudo-prime number in the ascendent
|
# pseudo-prime number in the ascendent
|
||||||
# order. It must generate all prime numbers,
|
# order. It must generate all prime numbers,
|
||||||
# but may generate non prime numbers.
|
# but may generate non prime numbers.
|
||||||
#
|
#
|
||||||
# === Exceptions
|
# === Exceptions
|
||||||
# +ZeroDivisionError+:: when +value+ is zero.
|
# +ZeroDivisionError+:: when +value+ is zero.
|
||||||
#
|
#
|
||||||
# == Example
|
# == Example
|
||||||
# For an arbitrary integer
|
# For an arbitrary integer
|
||||||
# n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
|
# n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
|
||||||
# prime_division(n) returns
|
# prime_division(n) returns
|
||||||
# [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
|
# [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
|
||||||
#
|
#
|
||||||
# Prime.prime_division(12) #=> [[2,2], [3,1]]
|
# Prime.prime_division(12) #=> [[2,2], [3,1]]
|
||||||
#
|
#
|
||||||
def prime_division(value, generator= Prime::Generator23.new)
|
def prime_division(value, generator= Prime::Generator23.new)
|
||||||
raise ZeroDivisionError if value == 0
|
raise ZeroDivisionError if value == 0
|
||||||
if value < 0
|
if value < 0
|
||||||
value = -value
|
value = -value
|
||||||
|
@ -216,12 +216,12 @@ class Prime
|
||||||
pv.push [value, 1]
|
pv.push [value, 1]
|
||||||
end
|
end
|
||||||
return pv
|
return pv
|
||||||
end
|
end
|
||||||
|
|
||||||
# An abstract class for enumerating pseudo-prime numbers.
|
# An abstract class for enumerating pseudo-prime numbers.
|
||||||
#
|
#
|
||||||
# Concrete subclasses should override succ, next, rewind.
|
# Concrete subclasses should override succ, next, rewind.
|
||||||
class PseudoPrimeGenerator
|
class PseudoPrimeGenerator
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
def initialize(ubound = nil)
|
def initialize(ubound = nil)
|
||||||
|
@ -282,12 +282,12 @@ class Prime
|
||||||
yield prime, obj
|
yield prime, obj
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# An implementation of +PseudoPrimeGenerator+.
|
# An implementation of +PseudoPrimeGenerator+.
|
||||||
#
|
#
|
||||||
# Uses +EratosthenesSieve+.
|
# Uses +EratosthenesSieve+.
|
||||||
class EratosthenesGenerator < PseudoPrimeGenerator
|
class EratosthenesGenerator < PseudoPrimeGenerator
|
||||||
def initialize
|
def initialize
|
||||||
@last_prime = nil
|
@last_prime = nil
|
||||||
super
|
super
|
||||||
|
@ -300,11 +300,11 @@ class Prime
|
||||||
initialize
|
initialize
|
||||||
end
|
end
|
||||||
alias next succ
|
alias next succ
|
||||||
end
|
end
|
||||||
|
|
||||||
# An implementation of +PseudoPrimeGenerator+ which uses
|
# An implementation of +PseudoPrimeGenerator+ which uses
|
||||||
# a prime table generated by trial division.
|
# a prime table generated by trial division.
|
||||||
class TrialDivisionGenerator<PseudoPrimeGenerator
|
class TrialDivisionGenerator<PseudoPrimeGenerator
|
||||||
def initialize
|
def initialize
|
||||||
@index = -1
|
@index = -1
|
||||||
super
|
super
|
||||||
|
@ -317,15 +317,15 @@ class Prime
|
||||||
initialize
|
initialize
|
||||||
end
|
end
|
||||||
alias next succ
|
alias next succ
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates all integer which are greater than 2 and
|
# Generates all integer which are greater than 2 and
|
||||||
# are not divided by 2 nor 3.
|
# are not divided by 2 nor 3.
|
||||||
#
|
#
|
||||||
# This is a pseudo-prime generator, suitable on
|
# This is a pseudo-prime generator, suitable on
|
||||||
# checking primality of a integer by brute force
|
# checking primality of a integer by brute force
|
||||||
# method.
|
# method.
|
||||||
class Generator23<PseudoPrimeGenerator
|
class Generator23<PseudoPrimeGenerator
|
||||||
def initialize
|
def initialize
|
||||||
@prime = 1
|
@prime = 1
|
||||||
@step = nil
|
@step = nil
|
||||||
|
@ -351,13 +351,13 @@ class Prime
|
||||||
def rewind
|
def rewind
|
||||||
initialize
|
initialize
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Internal use. An implementation of prime table by trial division method.
|
# Internal use. An implementation of prime table by trial division method.
|
||||||
class TrialDivision
|
class TrialDivision
|
||||||
include Singleton
|
include Singleton
|
||||||
|
|
||||||
def initialize # :nodoc:
|
def initialize # :nodoc:
|
||||||
|
@ -402,10 +402,10 @@ class Prime
|
||||||
end
|
end
|
||||||
return @primes[index]
|
return @primes[index]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal use. An implementation of eratosthenes's sieve
|
# Internal use. An implementation of eratosthenes's sieve
|
||||||
class EratosthenesSieve
|
class EratosthenesSieve
|
||||||
include Singleton
|
include Singleton
|
||||||
|
|
||||||
BITS_PER_ENTRY = 16 # each entry is a set of 16-bits in a Fixnum
|
BITS_PER_ENTRY = 16 # each entry is a set of 16-bits in a Fixnum
|
||||||
|
@ -471,10 +471,10 @@ class Prime
|
||||||
end
|
end
|
||||||
@tables << new_table.freeze
|
@tables << new_table.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Provides a +Prime+ object with compatibility to Ruby 1.8 when instantiated via +Prime+.+new+.
|
# Provides a +Prime+ object with compatibility to Ruby 1.8 when instantiated via +Prime+.+new+.
|
||||||
module OldCompatibility
|
module OldCompatibility
|
||||||
# Returns the next prime number and forwards internal pointer.
|
# Returns the next prime number and forwards internal pointer.
|
||||||
def succ
|
def succ
|
||||||
@generator.succ
|
@generator.succ
|
||||||
|
@ -491,5 +491,5 @@ class Prime
|
||||||
yield succ
|
yield succ
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
require 'rexml/xmltokens'
|
require 'rexml/xmltokens'
|
||||||
|
|
||||||
# [ :element, parent, name, attributes, children* ]
|
# [ :element, parent, name, attributes, children* ]
|
||||||
# a = Node.new
|
# a = Node.new
|
||||||
# a << "B" # => <a>B</a>
|
# a << "B" # => <a>B</a>
|
||||||
# a.b # => <a>B<b/></a>
|
# a.b # => <a>B<b/></a>
|
||||||
# a.b[1] # => <a>B<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[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[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.b.c << "D" # => <a>B<b><c>D</c></b><b x="y"/></a>
|
||||||
module REXML
|
module REXML
|
||||||
module Light
|
module Light
|
||||||
# Represents a tagged XML element. Elements are characterized by
|
# Represents a tagged XML element. Elements are characterized by
|
||||||
|
|
|
@ -17,7 +17,7 @@ module RSS
|
||||||
class ImageItem < ImageItemBase
|
class ImageItem < ImageItemBase
|
||||||
DublinCoreModel.install_dublin_core(self)
|
DublinCoreModel.install_dublin_core(self)
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
class ImageItemBase < Base
|
class ImageItemBase < Base
|
||||||
|
|
|
@ -209,7 +209,7 @@ module RSS
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias_method(:install_have_attribute_element, :install_have_child_element)
|
alias_method(:install_have_attribute_element, :install_have_child_element)
|
||||||
|
@ -230,7 +230,7 @@ EOC
|
||||||
rv << value if /\\A\\s*\\z/ !~ value
|
rv << value if /\\A\\s*\\z/ !~ value
|
||||||
end
|
end
|
||||||
rv.join("\n")
|
rv.join("\n")
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ EOC
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -295,7 +295,7 @@ EOC
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -310,7 +310,7 @@ EOC
|
||||||
#{yield(name, elem_name)}
|
#{yield(name, elem_name)}
|
||||||
end
|
end
|
||||||
private :#{method_name}
|
private :#{method_name}
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
def inherit_convert_attr_reader(*attrs)
|
def inherit_convert_attr_reader(*attrs)
|
||||||
|
@ -330,7 +330,7 @@ EOC
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ EOC
|
||||||
"\#{base}\#{value}"
|
"\#{base}\#{value}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ EOC
|
||||||
def #{attr}
|
def #{attr}
|
||||||
convert(@#{attr})
|
convert(@#{attr})
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
def integer_writer(name, disp_name=name)
|
def integer_writer(name, disp_name=name)
|
||||||
|
@ -468,7 +468,7 @@ EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
def positive_integer_writer(name, disp_name=name)
|
def positive_integer_writer(name, disp_name=name)
|
||||||
|
@ -490,7 +490,7 @@ EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
def boolean_writer(name, disp_name=name)
|
def boolean_writer(name, disp_name=name)
|
||||||
|
@ -510,7 +510,7 @@ EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_type_writer(name, disp_name=name)
|
def text_type_writer(name, disp_name=name)
|
||||||
|
@ -522,7 +522,7 @@ EOC
|
||||||
end
|
end
|
||||||
@#{name} = new_value
|
@#{name} = new_value
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_writer(name, disp_name=name)
|
def content_writer(name, disp_name=name)
|
||||||
|
@ -536,7 +536,7 @@ EOC
|
||||||
@#{name}.content = new_value
|
@#{name}.content = new_value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
def yes_clean_other_writer(name, disp_name=name)
|
def yes_clean_other_writer(name, disp_name=name)
|
||||||
|
@ -603,7 +603,7 @@ EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias_method(:set_#{accessor_name}, :#{accessor_name}=)
|
alias_method(:set_#{accessor_name}, :#{accessor_name}=)
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
58
lib/scanf.rb
58
lib/scanf.rb
|
@ -578,33 +578,33 @@ end
|
||||||
|
|
||||||
class IO
|
class IO
|
||||||
|
|
||||||
# The trick here is doing a match where you grab one *line*
|
# The trick here is doing a match where you grab one *line*
|
||||||
# of input at a time. The linebreak may or may not occur
|
# of input at a time. The linebreak may or may not occur
|
||||||
# at the boundary where the string matches a format specifier.
|
# at the boundary where the string matches a format specifier.
|
||||||
# And if it does, some rule about whitespace may or may not
|
# And if it does, some rule about whitespace may or may not
|
||||||
# be in effect...
|
# be in effect...
|
||||||
#
|
#
|
||||||
# That's why this is much more elaborate than the string
|
# That's why this is much more elaborate than the string
|
||||||
# version.
|
# version.
|
||||||
#
|
#
|
||||||
# For each line:
|
# For each line:
|
||||||
# Match succeeds (non-emptily)
|
# Match succeeds (non-emptily)
|
||||||
# and the last attempted spec/string sub-match succeeded:
|
# and the last attempted spec/string sub-match succeeded:
|
||||||
#
|
#
|
||||||
# could the last spec keep matching?
|
# could the last spec keep matching?
|
||||||
# yes: save interim results and continue (next line)
|
# yes: save interim results and continue (next line)
|
||||||
#
|
#
|
||||||
# The last attempted spec/string did not match:
|
# The last attempted spec/string did not match:
|
||||||
#
|
#
|
||||||
# are we on the next-to-last spec in the string?
|
# are we on the next-to-last spec in the string?
|
||||||
# yes:
|
# yes:
|
||||||
# is fmt_string.string_left all spaces?
|
# is fmt_string.string_left all spaces?
|
||||||
# yes: does current spec care about input space?
|
# yes: does current spec care about input space?
|
||||||
# yes: fatal failure
|
# yes: fatal failure
|
||||||
# no: save interim results and continue
|
# no: save interim results and continue
|
||||||
# no: continue [this state could be analyzed further]
|
# no: continue [this state could be analyzed further]
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def scanf(str,&b)
|
def scanf(str,&b)
|
||||||
return block_scanf(str,&b) if b
|
return block_scanf(str,&b) if b
|
||||||
|
@ -671,8 +671,8 @@ class IO
|
||||||
|
|
||||||
def block_scanf(str)
|
def block_scanf(str)
|
||||||
final = []
|
final = []
|
||||||
# Sub-ideal, since another FS gets created in scanf.
|
# Sub-ideal, since another FS gets created in scanf.
|
||||||
# But used here to determine the number of specifiers.
|
# But used here to determine the number of specifiers.
|
||||||
fstr = Scanf::FormatString.new(str)
|
fstr = Scanf::FormatString.new(str)
|
||||||
last_spec = fstr.last_spec
|
last_spec = fstr.last_spec
|
||||||
begin
|
begin
|
||||||
|
|
106
lib/set.rb
106
lib/set.rb
|
@ -351,11 +351,11 @@ class Set
|
||||||
n = Set.new(enum)
|
n = Set.new(enum)
|
||||||
each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
|
each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
|
||||||
n
|
n
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if two sets are equal. The equality of each couple
|
# Returns true if two sets are equal. The equality of each couple
|
||||||
# of elements is defined according to Object#eql?.
|
# of elements is defined according to Object#eql?.
|
||||||
def ==(other)
|
def ==(other)
|
||||||
if self.equal?(other)
|
if self.equal?(other)
|
||||||
true
|
true
|
||||||
elsif other.instance_of?(self.class)
|
elsif other.instance_of?(self.class)
|
||||||
|
@ -365,31 +365,31 @@ class Set
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def hash # :nodoc:
|
def hash # :nodoc:
|
||||||
@hash.hash
|
@hash.hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def eql?(o) # :nodoc:
|
def eql?(o) # :nodoc:
|
||||||
return false unless o.is_a?(Set)
|
return false unless o.is_a?(Set)
|
||||||
@hash.eql?(o.instance_eval{@hash})
|
@hash.eql?(o.instance_eval{@hash})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Classifies the set by the return value of the given block and
|
# Classifies the set by the return value of the given block and
|
||||||
# returns a hash of {value => set of elements} pairs. The block is
|
# returns a hash of {value => set of elements} pairs. The block is
|
||||||
# called once for each element of the set, passing the element as
|
# called once for each element of the set, passing the element as
|
||||||
# parameter.
|
# parameter.
|
||||||
#
|
#
|
||||||
# e.g.:
|
# e.g.:
|
||||||
#
|
#
|
||||||
# require 'set'
|
# require 'set'
|
||||||
# files = Set.new(Dir.glob("*.rb"))
|
# files = Set.new(Dir.glob("*.rb"))
|
||||||
# hash = files.classify { |f| File.mtime(f).year }
|
# hash = files.classify { |f| File.mtime(f).year }
|
||||||
# p hash # => {2000=>#<Set: {"a.rb", "b.rb"}>,
|
# p hash # => {2000=>#<Set: {"a.rb", "b.rb"}>,
|
||||||
# # 2001=>#<Set: {"c.rb", "d.rb", "e.rb"}>,
|
# # 2001=>#<Set: {"c.rb", "d.rb", "e.rb"}>,
|
||||||
# # 2002=>#<Set: {"f.rb"}>}
|
# # 2002=>#<Set: {"f.rb"}>}
|
||||||
def classify # :yields: o
|
def classify # :yields: o
|
||||||
block_given? or return enum_for(__method__)
|
block_given? or return enum_for(__method__)
|
||||||
|
|
||||||
h = {}
|
h = {}
|
||||||
|
@ -400,25 +400,25 @@ class Set
|
||||||
}
|
}
|
||||||
|
|
||||||
h
|
h
|
||||||
end
|
end
|
||||||
|
|
||||||
# Divides the set into a set of subsets according to the commonality
|
# Divides the set into a set of subsets according to the commonality
|
||||||
# defined by the given block.
|
# defined by the given block.
|
||||||
#
|
#
|
||||||
# If the arity of the block is 2, elements o1 and o2 are in common
|
# 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
|
# if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are
|
||||||
# in common if block.call(o1) == block.call(o2).
|
# in common if block.call(o1) == block.call(o2).
|
||||||
#
|
#
|
||||||
# e.g.:
|
# e.g.:
|
||||||
#
|
#
|
||||||
# require 'set'
|
# require 'set'
|
||||||
# numbers = Set[1, 3, 4, 6, 9, 10, 11]
|
# numbers = Set[1, 3, 4, 6, 9, 10, 11]
|
||||||
# set = numbers.divide { |i,j| (i - j).abs == 1 }
|
# set = numbers.divide { |i,j| (i - j).abs == 1 }
|
||||||
# p set # => #<Set: {#<Set: {1}>,
|
# p set # => #<Set: {#<Set: {1}>,
|
||||||
# # #<Set: {11, 9, 10}>,
|
# # #<Set: {11, 9, 10}>,
|
||||||
# # #<Set: {3, 4}>,
|
# # #<Set: {3, 4}>,
|
||||||
# # #<Set: {6}>}>
|
# # #<Set: {6}>}>
|
||||||
def divide(&func)
|
def divide(&func)
|
||||||
func or return enum_for(__method__)
|
func or return enum_for(__method__)
|
||||||
|
|
||||||
if func.arity == 2
|
if func.arity == 2
|
||||||
|
@ -446,13 +446,13 @@ class Set
|
||||||
else
|
else
|
||||||
Set.new(classify(&func).values)
|
Set.new(classify(&func).values)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
InspectKey = :__inspect_key__ # :nodoc:
|
InspectKey = :__inspect_key__ # :nodoc:
|
||||||
|
|
||||||
# Returns a string containing a human-readable representation of the
|
# Returns a string containing a human-readable representation of the
|
||||||
# set. ("#<Set: {element1, element2, ...}>")
|
# set. ("#<Set: {element1, element2, ...}>")
|
||||||
def inspect
|
def inspect
|
||||||
ids = (Thread.current[InspectKey] ||= [])
|
ids = (Thread.current[InspectKey] ||= [])
|
||||||
|
|
||||||
if ids.include?(object_id)
|
if ids.include?(object_id)
|
||||||
|
@ -465,9 +465,9 @@ class Set
|
||||||
ensure
|
ensure
|
||||||
ids.pop
|
ids.pop
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pretty_print(pp) # :nodoc:
|
def pretty_print(pp) # :nodoc:
|
||||||
pp.text sprintf('#<%s: {', self.class.name)
|
pp.text sprintf('#<%s: {', self.class.name)
|
||||||
pp.nest(1) {
|
pp.nest(1) {
|
||||||
pp.seplist(self) { |o|
|
pp.seplist(self) { |o|
|
||||||
|
@ -475,11 +475,11 @@ class Set
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pp.text "}>"
|
pp.text "}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def pretty_print_cycle(pp) # :nodoc:
|
def pretty_print_cycle(pp) # :nodoc:
|
||||||
pp.text sprintf('#<%s: {%s}>', self.class.name, empty? ? '' : '...')
|
pp.text sprintf('#<%s: {%s}>', self.class.name, empty? ? '' : '...')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -1168,8 +1168,8 @@ class TC_Set < Test::Unit::TestCase
|
||||||
set2 = Set["a", "b", set1]
|
set2 = Set["a", "b", set1]
|
||||||
set1 = set1.add(set1.clone)
|
set1 = set1.add(set1.clone)
|
||||||
|
|
||||||
# assert_equal(set1, set2)
|
# assert_equal(set1, set2)
|
||||||
# assert_equal(set2, set1)
|
# assert_equal(set2, set1)
|
||||||
assert_equal(set2, set2.clone)
|
assert_equal(set2, set2.clone)
|
||||||
assert_equal(set1.clone, set1)
|
assert_equal(set1.clone, set1)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Shell
|
||||||
include Error
|
include Error
|
||||||
extend Exception2MessageMapper
|
extend Exception2MessageMapper
|
||||||
|
|
||||||
# @cascade = true
|
# @cascade = true
|
||||||
# debug: true -> normal debug
|
# debug: true -> normal debug
|
||||||
# debug: 1 -> eval definition debug
|
# debug: 1 -> eval definition debug
|
||||||
# debug: 2 -> detail inspect debug
|
# debug: 2 -> detail inspect debug
|
||||||
|
@ -41,7 +41,7 @@ class Shell
|
||||||
|
|
||||||
attr_accessor :cascade, :debug, :verbose
|
attr_accessor :cascade, :debug, :verbose
|
||||||
|
|
||||||
# alias cascade? cascade
|
# alias cascade? cascade
|
||||||
alias debug? debug
|
alias debug? debug
|
||||||
alias verbose? verbose
|
alias verbose? verbose
|
||||||
@verbose = true
|
@verbose = true
|
||||||
|
@ -286,7 +286,7 @@ class Shell
|
||||||
yield mes if iterator?
|
yield mes if iterator?
|
||||||
if _head
|
if _head
|
||||||
_head = false
|
_head = false
|
||||||
# "shell" " + mes
|
# "shell" " + mes
|
||||||
prefix + mes
|
prefix + mes
|
||||||
else
|
else
|
||||||
" "* prefix.size + mes
|
" "* prefix.size + mes
|
||||||
|
|
|
@ -83,19 +83,19 @@ class Shell
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# class Sort < Cat
|
# class Sort < Cat
|
||||||
# def initialize(sh, *filenames)
|
# def initialize(sh, *filenames)
|
||||||
# super
|
# super
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def each(rs = nil)
|
# def each(rs = nil)
|
||||||
# ary = []
|
# ary = []
|
||||||
# super{|l| ary.push l}
|
# super{|l| ary.push l}
|
||||||
# for l in ary.sort!
|
# for l in ary.sort!
|
||||||
# yield l
|
# yield l
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
class AppendIO < BuiltInCommand
|
class AppendIO < BuiltInCommand
|
||||||
def initialize(sh, io, filter)
|
def initialize(sh, io, filter)
|
||||||
|
|
|
@ -19,7 +19,7 @@ require "shell/builtin-command"
|
||||||
|
|
||||||
class Shell
|
class Shell
|
||||||
class CommandProcessor
|
class CommandProcessor
|
||||||
# include Error
|
# include Error
|
||||||
|
|
||||||
#
|
#
|
||||||
# initialize of Shell and related classes.
|
# initialize of Shell and related classes.
|
||||||
|
|
|
@ -157,19 +157,19 @@ class Shell
|
||||||
@waiting_jobs.delete command
|
@waiting_jobs.delete command
|
||||||
else
|
else
|
||||||
command = @waiting_jobs.shift
|
command = @waiting_jobs.shift
|
||||||
# command.notify "job(%id) pre-start.", @shell.debug?
|
# command.notify "job(%id) pre-start.", @shell.debug?
|
||||||
|
|
||||||
return unless command
|
return unless command
|
||||||
end
|
end
|
||||||
@active_jobs.push command
|
@active_jobs.push command
|
||||||
command.start
|
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
|
# start all jobs that input from the job
|
||||||
for job in @waiting_jobs.dup
|
for job in @waiting_jobs.dup
|
||||||
start_job(job) if job.input == command
|
start_job(job) if job.input == command
|
||||||
end
|
end
|
||||||
# command.notify "job(%id) post2-start.", @shell.debug?
|
# command.notify "job(%id) post2-start.", @shell.debug?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ class Shell
|
||||||
|
|
||||||
pid = fork {
|
pid = fork {
|
||||||
Thread.list.each do |th|
|
Thread.list.each do |th|
|
||||||
# th.kill unless [Thread.main, Thread.current].include?(th)
|
# th.kill unless [Thread.main, Thread.current].include?(th)
|
||||||
th.kill unless Thread.current == th
|
th.kill unless Thread.current == th
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -296,11 +296,11 @@ class Shell
|
||||||
redo
|
redo
|
||||||
end
|
end
|
||||||
|
|
||||||
# command.notify "job(%id) pre-pre-finish.", @shell.debug?
|
# command.notify "job(%id) pre-pre-finish.", @shell.debug?
|
||||||
@job_monitor.synchronize do
|
@job_monitor.synchronize do
|
||||||
# command.notify "job(%id) pre-finish.", @shell.debug?
|
# command.notify "job(%id) pre-finish.", @shell.debug?
|
||||||
terminate_job(command)
|
terminate_job(command)
|
||||||
# command.notify "job(%id) pre-finish2.", @shell.debug?
|
# command.notify "job(%id) pre-finish2.", @shell.debug?
|
||||||
@job_condition.signal
|
@job_condition.signal
|
||||||
command.notify "job(%id) finish.", @shell.debug?
|
command.notify "job(%id) finish.", @shell.debug?
|
||||||
end
|
end
|
||||||
|
|
|
@ -1323,9 +1323,11 @@ module URI
|
||||||
if rel.userinfo != oth.userinfo ||
|
if rel.userinfo != oth.userinfo ||
|
||||||
rel.host.to_s.downcase != oth.host.to_s.downcase ||
|
rel.host.to_s.downcase != oth.host.to_s.downcase ||
|
||||||
rel.port != oth.port
|
rel.port != oth.port
|
||||||
|
|
||||||
if self.userinfo.nil? && self.host.nil?
|
if self.userinfo.nil? && self.host.nil?
|
||||||
return self, self.dup
|
return self, self.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
rel.set_port(nil) if rel.port == oth.default_port
|
rel.set_port(nil) if rel.port == oth.default_port
|
||||||
return rel, rel
|
return rel, rel
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue