あおきです。
Ruby 1.8 で警告が出ていたので、以下のように変更して消しました。
* m (arg,arg) → m(arg,arg)
* a[m arg] → a[m(arg)]
* Object#type → Object#class
* String#split, sub, sub!, gsub, gsub!, scan の第一引数が文字列
→ 全部正規表現に
文字列のメソッドで警告の出る条件は正確には「第一引数が文字列
または文字列に変換される場合で、しかも str != Regexp.quote(str)
であるとき」です。ですがなぜか Regexp.quote(' ') != ' ' だったり
いろいろ謎なことが起こるので、前述のメソッドの第一引数は無条件に
正規表現にしておくのが無難だと思います。
リテラル以外も洗ったつもりですが、ちょっとは抜けがあるかも
しれません。
# tdiary/core tdiary/plugin として全部まとめて差分を取ってます。
-------------------------------------------------------------------
青木峰郎
diff -ur tdiary/core/misc/jtime.rb tdiary-devel/core/misc/jtime.rb
--- tdiary/core/misc/jtime.rb Mon Mar 4 22:47:26 2002
+++ tdiary-devel/core/misc/jtime.rb Fri Mar 21 01:38:52 2003
@@ -11,7 +11,7 @@
alias strftime_ strftime
JWDAY = %w(日 月 火 水 木 金 土)
def strftime( format )
- strftime_( format.gsub( '%J', JWDAY[self.wday] ) )
+ strftime_( format.gsub( /%J/, JWDAY[self.wday] ) )
end
end
diff -ur tdiary/core/misc/posttdiary.rb tdiary-devel/core/misc/posttdiary.rb
--- tdiary/core/misc/posttdiary.rb Sun Sep 29 01:23:16 2002
+++ tdiary-devel/core/misc/posttdiary.rb Fri Mar 21 01:50:10 2003
@@ -49,7 +49,7 @@
--image-url, -u: URL of image.
You have to specify both options when using images.
TEXT
- text.gsub( "\t", '' )
+ text.gsub( /\t/, '' )
end
def image_list( date, path )
@@ -130,7 +130,7 @@
mail = ARGF.read
raise "no mail text." if not mail or mail.length == 0
- head, body = mail.split( "\n\n", 2 )
+ head, body = mail.split( /\n\n/, 2 )
require 'base64'
require 'nkf'
@@ -142,9 +142,9 @@
end
bound = "--" + $1
- body_sub = body.split( Regexp.escape( bound ) )
+ body_sub = body.split( Regexp.compile( Regexp.escape( bound ) ) )
body_sub.each do |b|
- sub_head, sub_body = b.split( "\n\n", 2 )
+ sub_head, sub_body = b.split( /\n\n/, 2 )
next unless sub_head =~ /Content-Type/
diff -ur tdiary/core/misc/style/emptdiary/emptdiary_style.rb tdiary-devel/core/misc/style/emptdiary/emptdiary_style.rb
--- tdiary/core/misc/style/emptdiary/emptdiary_style.rb Thu Mar 6 08:42:18 2003
+++ tdiary-devel/core/misc/style/emptdiary/emptdiary_style.rb Fri Mar 21 01:55:11 2003
@@ -124,7 +124,7 @@
end
def append( body, author = nil )
- Emptdiary::EmptdiaryString.new(body.gsub( "\r", '' )).split_unless_plugin( "\n\n+" ).each do |fragment|
+ Emptdiary::EmptdiaryString.new(body.gsub( /\r/, '' )).split_unless_plugin( "\n\n+" ).each do |fragment|
section = EmptdiarySection::new( fragment, author )
@sections << section if section
end
diff -ur tdiary/core/misc/style/etdiary/etdiary_style.rb tdiary-devel/core/misc/style/etdiary/etdiary_style.rb
--- tdiary/core/misc/style/etdiary/etdiary_style.rb Thu Mar 6 08:42:19 2003
+++ tdiary-devel/core/misc/style/etdiary/etdiary_style.rb Fri Mar 21 01:54:52 2003
@@ -238,7 +238,7 @@
section = EtdiarySection::new( nil, author )
buffer = nil
tag_kind = nil
- ( body.gsub("\r",'').sub(/\A\n*/,'') + "\n" ).each("") do |fragment|
+ ( body.gsub(/\r/,'').sub(/\A\n*/,'') + "\n" ).each("") do |fragment|
if buffer and TAG_END_REGEXP =~ fragment and $2.downcase == tag_kind then
section << buffer + fragment.sub(/\n*\z/,"\n\n")
tag_kind = nil
@@ -291,7 +291,7 @@
section.bodies.each do |fragment|
if PRE_REGEXP =~ fragment then
r << factory.pre_start
- r << $1.gsub("&","&").gsub("<","<").gsub(">",">")
+ r << $1.gsub(/&/,"&").gsub(/</,"<").gsub(/>/,">")
r << factory.pre_end << "\n"
elsif /\A</ =~ fragment then
r << fragment.sub( /\n*\z/, "\n" )
diff -ur tdiary/core/misc/style/rd/rd_style.rb tdiary-devel/core/misc/style/rd/rd_style.rb
--- tdiary/core/misc/style/rd/rd_style.rb Sat Mar 8 10:45:47 2003
+++ tdiary-devel/core/misc/style/rd/rd_style.rb Fri Mar 21 01:54:09 2003
@@ -74,7 +74,7 @@
def apply_to_RefToElement(element, content)
label = element.to_label
- key, opt = label.split(":", 2)
+ key, opt = label.split(/:/, 2)
case key
when "IMG"
diff -ur tdiary/core/misc/style/wiki/wiki_style.rb tdiary-devel/core/misc/style/wiki/wiki_style.rb
--- tdiary/core/misc/style/wiki/wiki_style.rb Wed Mar 5 10:32:46 2003
+++ tdiary-devel/core/misc/style/wiki/wiki_style.rb Fri Mar 21 01:48:47 2003
@@ -154,7 +154,7 @@
case stat
when :KS
if /\|/ =~ s
- k, u = s.split( '|', 2 )
+ k, u = s.split( /\|/, 2 )
if /^(\d{4}|\d{6}|\d{8})[^\d]*?#?([pc]\d\d)?$/ =~ u then
r << "%=my '" << $1
r << $2 if $2
@@ -290,7 +290,7 @@
case stat
when :KS
if /\|/ =~ s
- k, u = s.split( '|', 2 )
+ k, u = s.split( /\|/, 2 )
if /^(\d{4}|\d{6}|\d{8})[^\d]*?#?([pc]\d\d)?$/ =~ u then
r << "%=my '" << $1
r << $2 if $2
diff -ur tdiary/core/misc/theme_convert/theme_convert.rb tdiary-devel/core/misc/theme_convert/theme_convert.rb
--- tdiary/core/misc/theme_convert/theme_convert.rb Sun Jan 19 17:21:45 2003
+++ tdiary-devel/core/misc/theme_convert/theme_convert.rb Fri Mar 21 02:36:23 2003
@@ -374,7 +374,7 @@
]
flag = false
- File.open ( fname.sub( /\.css/i, "-2.css" ), "w" ) do |f|
+ File.open( fname.sub( /\.css/i, "-2.css" ), "w" ) do |f|
File.open( fname, "r" ) do |file|
file.each {|line|
if /\{/ =~ line
@@ -404,7 +404,7 @@
end
rcss = File::readlines( "append.rcss" ).join
- File.open ( fname.sub( /\.css/i, "-2.css" ), "a" ) do |f|
+ File.open( fname.sub( /\.css/i, "-2.css" ), "a" ) do |f|
f.write( ERbLight::new( rcss ).result( binding ) )
end
end
diff -ur tdiary/core/skel/plugin_error.rhtml tdiary-devel/core/skel/plugin_error.rhtml
--- tdiary/core/skel/plugin_error.rhtml Tue Nov 12 18:00:53 2002
+++ tdiary-devel/core/skel/plugin_error.rhtml Fri Mar 21 01:39:15 2003
@@ -11,8 +11,8 @@
Retry to <a href="<%= @conf.update %>">Update</a> or <a href="<%= @conf.update %>?conf=OK">Configure</a>.
</strong></p>
<blockquote>
- <strong><%= CGI::escapeHTML( $!.type.to_s ) %></strong><br>
- <code><%= CGI::escapeHTML( $!.to_s ).gsub( ' ', ' ' ).gsub( "\n", "<br>\n" ) %></code>
+ <strong><%= CGI::escapeHTML( $!.class.to_s ) %></strong><br>
+ <code><%= CGI::escapeHTML( $!.to_s ).gsub( / /, ' ' ).gsub( /\n/, "<br>\n" ) %></code>
</blockquote>
</body>
</html>
diff -ur tdiary/core/tdiary/defaultio.rb tdiary-devel/core/tdiary/defaultio.rb
--- tdiary/core/tdiary/defaultio.rb Wed Feb 12 23:24:26 2003
+++ tdiary-devel/core/tdiary/defaultio.rb Fri Mar 21 01:49:05 2003
@@ -7,7 +7,7 @@
TDIARY_MAGIC = "#{TDIARY_MAGIC_MAJOR}.#{TDIARY_MAGIC_MINOR}"
def TDiary::parse_tdiary( data )
- header, body = data.split( "\n\n", 2 )
+ header, body = data.split( /\n\n/, 2 )
if header and body
body.gsub!( /^\./, '' )
headers = {}
@@ -75,7 +75,7 @@
headers, body = TDiary::parse_tdiary( l )
next unless body
body.each do |r|
- count, ref = r.chomp.split( ' ', 2 )
+ count, ref = r.chomp.split( / /, 2 )
next unless ref
diaries[headers['Date']].add_referer( ref.chomp, count.to_i )
end
@@ -171,7 +171,7 @@
def restore( fh, diaries )
fh.seek( 0 )
begin
- major, minor = fh.gets.split( '.', 2 )
+ major, minor = fh.gets.split( /\./, 2 )
unless TDiary::TDIARY_MAGIC_MAJOR == major then
raise StandardError, 'bad file format.'
end
diff -ur tdiary/core/tdiary/pstoreio.rb tdiary-devel/core/tdiary/pstoreio.rb
--- tdiary/core/tdiary/pstoreio.rb Wed Feb 12 23:24:26 2003
+++ tdiary-devel/core/tdiary/pstoreio.rb Fri Mar 21 01:37:54 2003
@@ -145,7 +145,7 @@
end
def append( body, author = nil )
- body.gsub( "\r", '' ).split( /\n\n+/ ).each do |fragment|
+ body.gsub( /\r/, '' ).split( /\n\n+/ ).each do |fragment|
paragraph = Paragraph::new( fragment, author )
@paragraphs << paragraph if paragraph
end
diff -ur tdiary/core/tdiary/tdiary_style.rb tdiary-devel/core/tdiary/tdiary_style.rb
--- tdiary/core/tdiary/tdiary_style.rb Thu Mar 6 08:42:19 2003
+++ tdiary-devel/core/tdiary/tdiary_style.rb Fri Mar 21 01:38:07 2003
@@ -89,7 +89,7 @@
end
def append( body, author = nil )
- body.gsub( "\r", '' ).split( /\n\n+/ ).each do |fragment|
+ body.gsub( /\r/, '' ).split( /\n\n+/ ).each do |fragment|
section = TdiarySection::new( fragment, author )
@sections << section if section
end
diff -ur tdiary/core/tdiary.rb tdiary-devel/core/tdiary.rb
--- tdiary/core/tdiary.rb Thu Mar 20 00:26:06 2003
+++ tdiary-devel/core/tdiary.rb Fri Mar 21 02:53:28 2003
@@ -44,7 +44,7 @@
end
def shorten( len = 120 )
- lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( "\n", ' ' ) ).split( "\n" )
+ lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
lines[0].concat( '...' ) if lines[0] and lines[1]
lines[0]
end
@@ -369,7 +369,7 @@
load
instance_variables.each do |v|
- v.sub!( '@', '' )
+ v.sub!( /@/, '' )
instance_eval( <<-SRC
def #{v}
@#{v}
@@ -388,8 +388,8 @@
@index_page = cgi.params['index_page'][0]
@html_title = cgi.params['html_title'][0].to_euc
- @header = cgi.params['header'][0].to_euc.gsub( "\r\n", "\n" ).gsub( "\r", '' ).sub( /\n+\z/, '' )
- @footer = cgi.params['footer'][0].to_euc.gsub( "\r\n", "\n" ).gsub( "\r", '' ).sub( /\n+\z/, '' )
+ @header = cgi.params['header'][0].to_euc.gsub( /\r\n/, "\n" ).gsub( /\r/, '' ).sub( /\n+\z/, '' )
+ @footer = cgi.params['footer'][0].to_euc.gsub( /\r\n/, "\n" ).gsub( /\r/, '' ).sub( /\n+\z/, '' )
@section_anchor = cgi.params['section_anchor'][0].to_euc
@comment_anchor = cgi.params['comment_anchor'][0].to_euc
@@ -1245,7 +1245,7 @@
date = now.strftime( "%a, %d %b %Y %X " ) + sprintf( "%+05d", tz )
serial = @diary.count_comments( true )
- message_id = %Q|<tdiary.#{[@conf.mail_header].pack('m').gsub("\n",'')}.#{now.strftime('%Y%m%d%H%M%S')}.#{serial}@#{Socket::gethostname.sub(/^.+?\./,'')}>|
+ message_id = %Q|<tdiary.#{[@conf.mail_header].pack('m').gsub(/\n/,'')}.#{now.strftime('%Y%m%d%H%M%S')}.#{serial}@#{Socket::gethostname.sub(/^.+?\./,'')}>|
mail_header = @conf.mail_header.dup
mail_header << ":#{@conf.date_format}" unless /%[a-zA-Z%]/ =~ mail_header
@@ -1287,7 +1287,7 @@
def to_mime( str )
NKF::nkf( "-j -m0 -f50", str ).collect do |s|
- %Q||
+ %Q||
end
end
end
diff -ur tdiary/plugin/a/a_conf.rb tdiary-devel/plugin/a/a_conf.rb
--- tdiary/plugin/a/a_conf.rb Wed Mar 5 00:48:02 2003
+++ tdiary-devel/plugin/a/a_conf.rb Fri Mar 21 02:30:53 2003
@@ -72,7 +72,7 @@
open( path, 'w' ) do |o|
@cgi["anchor_plugin_data"].each do |v|
- v.split("\n").each do |line|
+ v.split(/\n/).each do |line|
o.print line, "\n" if line =~ /\w/
end
end
@@ -116,7 +116,7 @@
print body if /HEAD/i !~ @cgi.request_method
rescue Exception
puts "Content-Type: text/plain\n\n"
- puts "#$! (#{$!.type})"
+ puts "#$! (#{$!.class})"
puts ""
puts $@.join( "\n" )
end
diff -ur tdiary/plugin/bq.rb tdiary-devel/plugin/bq.rb
--- tdiary/plugin/bq.rb Tue Apr 16 14:55:43 2002
+++ tdiary-devel/plugin/bq.rb Fri Mar 21 02:30:34 2003
@@ -34,7 +34,7 @@
else
result = %Q[<blockquote>\n]
end
- result << %Q[<p>#{src.gsub( /\n/, "</p>\n<p>" )}</p>\n].sub( '<p></p>', '' )
+ result << %Q[<p>#{src.gsub( /\n/, "</p>\n<p>" )}</p>\n].sub( %r[<p></p>], '' )
result << %Q[</blockquote>\n]
if url then
result << %Q[<p class="source">[<cite><a href="#{url}" title="#{title}より引用">#{title}</a></cite>より引用]</p>\n]
diff -ur tdiary/plugin/calendar3.rb tdiary-devel/plugin/calendar3.rb
--- tdiary/plugin/calendar3.rb Sun Mar 2 23:07:34 2003
+++ tdiary-devel/plugin/calendar3.rb Fri Mar 21 02:29:52 2003
@@ -113,7 +113,7 @@
end
def shorten(str, len = 120)
- lines = NKF::nkf("-e -m0 -f" + len.to_s, str.gsub(/<.+?>/, '')).split("\n")
+ lines = NKF::nkf("-e -m0 -f" + len.to_s, str.gsub(/<.+?>/, '')).split(/\n/)
lines[0].concat('...') if lines[0] and lines[1]
lines[0]
end
diff -ur tdiary/plugin/kw.rb tdiary-devel/plugin/kw.rb
--- tdiary/plugin/kw.rb Tue Feb 18 22:40:44 2003
+++ tdiary-devel/plugin/kw.rb Fri Mar 21 02:29:40 2003
@@ -28,7 +28,7 @@
@kw_dic[dic[0]] = dic[1..-1]
end
end
- inter, key = keyword.split( ':', 2 )
+ inter, key = keyword.split( /:/, 2 )
unless key then
inter = nil
key = keyword
diff -ur tdiary/plugin/nazo.rb tdiary-devel/plugin/nazo.rb
--- tdiary/plugin/nazo.rb Tue Feb 11 17:13:55 2003
+++ tdiary-devel/plugin/nazo.rb Fri Mar 21 02:29:32 2003
@@ -59,9 +59,9 @@
hiliteElement(document.location.hash.substr(1));
}
- hereURL = document.location.href.split("#")[0];
+ hereURL = document.location.href.split(/\#/)[0];
for( var i = 0; i < document.links.length; i++ ){
- if( hereURL == document.links[i].href.split("#")[0] ){
+ if( hereURL == document.links[i].href.split(/\#/)[0] ){
document.links[i].onclick = handleLinkClick;
}
}
diff -ur tdiary/plugin/recent_comment3.rb tdiary-devel/plugin/recent_comment3.rb
--- tdiary/plugin/recent_comment3.rb Tue Mar 4 19:07:27 2003
+++ tdiary-devel/plugin/recent_comment3.rb Fri Mar 21 02:36:38 2003
@@ -43,7 +43,7 @@
name = @cgi.params['name'][0].to_euc
body = @cgi.params['body'][0].to_euc
comment = Comment.new(name, nil, body)
- serial = @diaries[@date.strftime '%Y%m%d'].count_comments
+ serial = @diaries[@date.strftime('%Y%m%d')].count_comments
if not (name.strip.empty? or body.strip.empty?)
PStore.new(RECENT_COMMENT3_CACHE).transaction do |db|
db['comments'] = Array.new(RECENT_COMMENT3_NUM) unless db.root?('comments')
diff -ur tdiary/plugin/recent_namazu.rb tdiary-devel/plugin/recent_namazu.rb
--- tdiary/plugin/recent_namazu.rb Wed Apr 24 12:23:42 2002
+++ tdiary-devel/plugin/recent_namazu.rb Fri Mar 21 02:29:18 2003
@@ -28,7 +28,7 @@
result = []
lines.reverse.each_with_index do |line,idx|
break if idx >= limit
- word = line.split('\t')[0]
+ word = line.split(/\t/)[0]
if make_link
result << %Q[<a href="#{namazu}?query=#{CGI::escapeHTML(word)}">#{CGI::escapeHTML(word)}</a>]
else
@@ -37,6 +37,6 @@
end
result.join( sep )
rescue
- %Q[<p class="message">#$! (#{$!.type})<br>cannot read #{file}.</p>]
+ %Q[<p class="message">#$! (#{$!.class})<br>cannot read #{file}.</p>]
end
end
diff -ur tdiary/plugin/todo/todo.rb tdiary-devel/plugin/todo/todo.rb
--- tdiary/plugin/todo/todo.rb Tue Mar 4 19:07:27 2003
+++ tdiary-devel/plugin/todo/todo.rb Fri Mar 21 02:29:08 2003
@@ -234,7 +234,7 @@
print body if /HEAD/i !~ @cgi.request_method
rescue Exception
puts "Content-Type: text/plain\n\n"
- puts "#$! (#{$!.type})"
+ puts "#$! (#{$!.class})"
puts ""
puts $@.join( "\n" )
end
|