From 29cef5f795043a048a58874d90de0dfe01aa12ea Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 2 Oct 2002 16:45:35 +0000 Subject: [PATCH] use Object#class instead of deprecated Object#type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/date.rb | 50 +++++++++++++++++----------------- lib/date/format.rb | 4 +-- lib/debug.rb | 6 ++-- lib/e2mmap.rb | 2 +- lib/irb.rb | 6 ++-- lib/irb/completion.rb | 2 +- lib/irb/context.rb | 2 +- lib/irb/init.rb | 4 +-- lib/matrix.rb | 12 ++++---- lib/net/pop.rb | 6 ++-- lib/net/protocol.rb | 8 +++--- lib/optparse.rb | 8 +++--- lib/ostruct.rb | 4 +-- lib/racc/parser.rb | 8 +++--- lib/resolv.rb | 6 ++-- lib/set.rb | 24 ++++++++-------- lib/shell/command-processor.rb | 4 +-- lib/shell/filter.rb | 6 ++-- lib/shell/system-command.rb | 4 +-- lib/singleton.rb | 4 +-- lib/tracer.rb | 6 ++-- lib/uri/generic.rb | 8 +++--- 22 files changed, 91 insertions(+), 93 deletions(-) diff --git a/lib/date.rb b/lib/date.rb index 79a3eda3dd..51cc95ee18 100644 --- a/lib/date.rb +++ b/lib/date.rb @@ -264,20 +264,20 @@ class Date def initialize(ajd=0, of=0, sg=ITALY) @ajd, @of, @sg = ajd, of, sg end def ajd() @ajd end - def amjd() type.ajd_to_amjd(@ajd) end + def amjd() self.class.ajd_to_amjd(@ajd) end once :amjd - def jd() type.ajd_to_jd(@ajd, @of)[0] end - def day_fraction() type.ajd_to_jd(@ajd, @of)[1] end - def mjd() type.jd_to_mjd(jd) end - def ld() type.jd_to_ld(jd) end + def jd() self.class.ajd_to_jd(@ajd, @of)[0] end + def day_fraction() self.class.ajd_to_jd(@ajd, @of)[1] end + def mjd() self.class.jd_to_mjd(jd) end + def ld() self.class.jd_to_ld(jd) end once :jd, :day_fraction, :mjd, :ld - def civil() type.jd_to_civil(jd, @sg) end - def ordinal() type.jd_to_ordinal(jd, @sg) end - def commercial() type.jd_to_commercial(jd, @sg) end + def civil() self.class.jd_to_civil(jd, @sg) end + def ordinal() self.class.jd_to_ordinal(jd, @sg) end + def commercial() self.class.jd_to_commercial(jd, @sg) end once :civil, :ordinal, :commercial private :civil, :ordinal, :commercial @@ -290,7 +290,7 @@ class Date alias_method :month, :mon alias_method :day, :mday - def time() type.day_fraction_to_time(day_fraction) end + def time() self.class.day_fraction_to_time(day_fraction) end once :time private :time @@ -316,45 +316,45 @@ class Date def cweek() commercial[1] end def cwday() commercial[2] end - def wday() type.jd_to_wday(jd) end + def wday() self.class.jd_to_wday(jd) end once :wday - def os? () type.os?(jd, @sg) end - def ns? () type.ns?(jd, @sg) end + def os? () self.class.os?(jd, @sg) end + def ns? () self.class.ns?(jd, @sg) end once :os?, :ns? def leap? - type.jd_to_civil(type.civil_to_jd(year, 3, 1, ns?) - 1, + self.class.jd_to_civil(self.class.civil_to_jd(year, 3, 1, ns?) - 1, ns?)[-1] == 29 end once :leap? def start() @sg end - def new_start(sg=type::ITALY) type.new0(@ajd, @of, sg) end + def new_start(sg=self.class::ITALY) self.class.new0(@ajd, @of, sg) end - def italy() new_start(type::ITALY) end - def england() new_start(type::ENGLAND) end - def julian() new_start(type::JULIAN) end - def gregorian() new_start(type::GREGORIAN) end + def italy() new_start(self.class::ITALY) end + def england() new_start(self.class::ENGLAND) end + def julian() new_start(self.class::JULIAN) end + def gregorian() new_start(self.class::GREGORIAN) end def offset() @of end - def new_offset(of=0) type.new0(@ajd, of, @sg) end + def new_offset(of=0) self.class.new0(@ajd, of, @sg) end private :offset, :new_offset def + (n) case n - when Numeric; return type.new0(@ajd + n, @of, @sg) + when Numeric; return self.class.new0(@ajd + n, @of, @sg) end raise TypeError, 'expected numeric' end def - (x) case x - when Numeric; return type.new0(@ajd - x, @of, @sg) + when Numeric; return self.class.new0(@ajd - x, @of, @sg) when Date; return @ajd - x.ajd end raise TypeError, 'expected numeric or date' @@ -380,7 +380,7 @@ class Date y, m = clfloor(year * 12 + (mon - 1) + n, 12) m, = clfloor(m + 1, 1) d = mday - d -= 1 until jd2 = type.valid_civil?(y, m, d, ns?) + d -= 1 until jd2 = self.class.valid_civil?(y, m, d, ns?) self + (jd2 - jd) end @@ -406,7 +406,7 @@ class Date def eql? (other) Date === other and self == other end def hash() @ajd.hash end - def inspect() format('#<%s: %s,%s,%s>', type, @ajd, @of, @sg) end + def inspect() format('#<%s: %s,%s,%s>', self.class, @ajd, @of, @sg) end def to_s() strftime end def _dump(limit) Marshal.dump([@ajd, @of, @sg], -1) end @@ -550,8 +550,8 @@ class Date def #{old}(*args, &block) if $VERBOSE $stderr.puts("\#{caller.shift.sub(/:in .*/, '')}: " \ - "warning: \#{type}\##{old} is deprecated; " \ - "use \#{type}\##{new}") + "warning: \#{self.class}\##{old} is deprecated; " \ + "use \#{self.class}\##{new}") end #{new}(*args, &block) end diff --git a/lib/date/format.rb b/lib/date/format.rb index e099854aa4..ac096f0751 100644 --- a/lib/date/format.rb +++ b/lib/date/format.rb @@ -483,13 +483,13 @@ class Date when '%r'; o << strftime('%I:%M:%S %p') # P2,ID when '%S'; o << '%02d' % sec when '%s' # TZ,GL - d = ajd - type.jd_to_ajd(type.civil_to_jd(1970,1,1), 0) + d = ajd - self.class.jd_to_ajd(type.civil_to_jd(1970,1,1), 0) s = (d * 86400).to_i o << '%d' % s when '%T'; o << strftime('%H:%M:%S') # P2,ID when '%t'; o << "\t" # P2,ID when '%U', '%W' - a = type.civil_to_jd(year, 1, 1, ns?) + 6 + a = self.class.civil_to_jd(year, 1, 1, ns?) + 6 k = if c == '%U' then 0 else 1 end w = (jd - (a - ((a - k) + 1) % 7) + 7) / 7 o << '%02d' % w diff --git a/lib/debug.rb b/lib/debug.rb index 16123c3d96..23a1df6047 100644 --- a/lib/debug.rb +++ b/lib/debug.rb @@ -666,13 +666,13 @@ EOHELP end def excn_handle(file, line, id, binding) - if $!.type <= SystemExit + if $!.class <= SystemExit set_trace_func nil exit end - if @catch and ($!.type.ancestors.find { |e| e.to_s == @catch }) - stdout.printf "%s:%d: `%s' (%s)\n", file, line, $!, $!.type + if @catch and ($!.class.ancestors.find { |e| e.to_s == @catch }) + stdout.printf "%s:%d: `%s' (%s)\n", file, line, $!, $!.class fs = @frames.size tb = caller(0)[-fs..-1] if tb diff --git a/lib/e2mmap.rb b/lib/e2mmap.rb index 6739c42518..3e2604af5d 100644 --- a/lib/e2mmap.rb +++ b/lib/e2mmap.rb @@ -69,7 +69,7 @@ module Exception2MessageMapper def bind(cl) self.module_eval %[ def Raise(err = nil, *rest) - Exception2MessageMapper.Raise(self.type, err, *rest) + Exception2MessageMapper.Raise(self.class, err, *rest) end alias Fail Raise diff --git a/lib/irb.rb b/lib/irb.rb index b5f12a66f8..a77585b641 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -149,8 +149,8 @@ module IRB output_value if @context.echo? rescue StandardError, ScriptError, Abort $! = RuntimeError.new("unknown exception raised") unless $! - print $!.type, ": ", $!, "\n" - if $@[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && $!.type.to_s !~ /^IRB/ + print $!.class, ": ", $!, "\n" + if $@[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && $!.class.to_s !~ /^IRB/ irb_bug = true else irb_bug = false @@ -307,7 +307,7 @@ module IRB ary.push format("%s=%s", iv, eval(iv)) end end - format("#<%s: %s>", type, ary.join(", ")) + format("#<%s: %s>", self.class, ary.join(", ")) end end diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index a350013e8e..30d60c2449 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -157,7 +157,7 @@ module IRB select_message(receiver, message, candidates) else - candidates = eval("methods | private_methods | local_variables | type.constants", bind) + candidates = eval("methods | private_methods | local_variables | self.class.constants", bind) (candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/) end diff --git a/lib/irb/context.rb b/lib/irb/context.rb index 1c504451cb..a041a001e4 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -164,7 +164,7 @@ module IRB end def file_input? - @io.type == FileInputMethod + @io.class == FileInputMethod end def inspect_mode=(opt) diff --git a/lib/irb/init.rb b/lib/irb/init.rb index f238153164..d883b78911 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -191,7 +191,7 @@ module IRB rescue LoadError, Errno::ENOENT rescue print "load error: #{rc}\n" - print $!.type, ": ", $!, "\n" + print $!.class, ": ", $!, "\n" for err in $@[0, $@.size - 2] print "\t", err, "\n" end @@ -208,7 +208,7 @@ module IRB begin require m rescue - print $@[0], ":", $!.type, ": ", $!, "\n" + print $@[0], ":", $!.class, ": ", $!, "\n" end end end diff --git a/lib/matrix.rb b/lib/matrix.rb index 8e092b0d0b..706252b091 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -688,7 +688,7 @@ class Matrix when Numeric return Scalar.new(other), self else - raise TypeError, "#{type} can't be coerced into #{other.type}" + raise TypeError, "#{self.class} can't be coerced into #{other.class}" end end @@ -751,7 +751,7 @@ class Matrix when Numeric Scalar.new(@value + other) when Vector, Matrix - Scalar.Raise WrongArgType, other.type, "Numeric or Scalar" + Scalar.Raise WrongArgType, other.class, "Numeric or Scalar" when Scalar Scalar.new(@value + other.value) else @@ -765,7 +765,7 @@ class Matrix when Numeric Scalar.new(@value - other) when Vector, Matrix - Scalar.Raise WrongArgType, other.type, "Numeric or Scalar" + Scalar.Raise WrongArgType, other.class, "Numeric or Scalar" when Scalar Scalar.new(@value - other.value) else @@ -791,7 +791,7 @@ class Matrix when Numeric Scalar.new(@value / other) when Vector - Scalar.Raise WrongArgType, other.type, "Numeric or Scalar or Matrix" + Scalar.Raise WrongArgType, other.class, "Numeric or Scalar or Matrix" when Matrix self * _M.inverse else @@ -805,7 +805,7 @@ class Matrix when Numeric Scalar.new(@value ** other) when Vector - Scalar.Raise WrongArgType, other.type, "Numeric or Scalar or Matrix" + Scalar.Raise WrongArgType, other.class, "Numeric or Scalar or Matrix" when Matrix other.powered_by(self) else @@ -1007,7 +1007,7 @@ class Vector when Numeric return Scalar.new(other), self else - raise TypeError, "#{type} can't be coerced into #{other.type}" + raise TypeError, "#{self.class} can't be coerced into #{other.class}" end end diff --git a/lib/net/pop.rb b/lib/net/pop.rb index af32e8835a..5966e6eecb 100644 --- a/lib/net/pop.rb +++ b/lib/net/pop.rb @@ -387,7 +387,7 @@ module Net def do_start( account, password ) conn_socket - @command = (@apop ? type.apop_command_type : type.command_type).new(socket()) + @command = (@apop ? self.class.apop_command_type : self.class.command_type).new(socket()) @command.auth account, password end @@ -408,7 +408,7 @@ module Net return @mails if @mails mails = [] - mtype = type.mail_type + mtype = self.class.mail_type command().list.each_with_index do |size,idx| mails.push mtype.new(idx, size, command()) if size end @@ -475,7 +475,7 @@ module Net attr :size def inspect - "#<#{type} #{@num}#{@deleted ? ' deleted' : ''}>" + "#<#{self.class} #{@num}#{@deleted ? ' deleted' : ''}>" end def pop( dest = '', &block ) diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index df38725cb9..bdb60e158d 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -424,7 +424,7 @@ module Net end def inspect - "#<#{type} #{closed? ? 'closed' : 'opened'}>" + "#<#{self.class} #{closed? ? 'closed' : 'opened'}>" end ### @@ -584,7 +584,7 @@ module Net public def write_message( src ) - D_off "writing text from #{src.type}" + D_off "writing text from #{src.class}" wsize = using_each_crlf_line { wpend_in src @@ -723,7 +723,7 @@ module Net end def inspect - "#<#{type} socket=#{@socket.inspect}>" + "#<#{self.class} socket=#{@socket.inspect}>" end def write( str ) @@ -755,7 +755,7 @@ module Net end def inspect - "#<#{type}>" + "#<#{self.class}>" end def <<( str ) diff --git a/lib/optparse.rb b/lib/optparse.rb index dc4564a4c5..c92af70c98 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -629,7 +629,7 @@ Default options, which never appear in option summary. end end def inc(*args) - type.inc(*args) + self.class.inc(*args) end =begin @@ -663,7 +663,7 @@ Default options, which never appear in option summary. string pushed back to be first non-option argument =end #'#"#`# def terminate(arg = nil) - type.terminate(arg) + self.class.terminate(arg) end def self.terminate(arg = nil) throw :terminate, arg @@ -1422,11 +1422,11 @@ Base class of exceptions from (()) end def reason - @reason || self.type::Reason + @reason || self.class::Reason end def inspect - '#<' + type.to_s + ': ' + args.join(' ') + '>' + "#<#{self.class.to_s}: #{args.join(' ')}>" end def message diff --git a/lib/ostruct.rb b/lib/ostruct.rb index f083677d8e..9106f6e068 100644 --- a/lib/ostruct.rb +++ b/lib/ostruct.rb @@ -35,14 +35,14 @@ class OpenStruct end def delete_field(name) - if name.type == Fixnum + if name.class == Fixnum name = name.id2name end @table.delete name end def inspect - str = "<#{self.type}" + str = "<#{self.class}" for k,v in @table str += " " str += k diff --git a/lib/racc/parser.rb b/lib/racc/parser.rb index ca581006d0..25590fa228 100644 --- a/lib/racc/parser.rb +++ b/lib/racc/parser.rb @@ -72,7 +72,7 @@ module Racc def _racc_setup - t = self.type + t = self.class unless t::Racc_debug_parser then @yydebug = false @@ -115,7 +115,7 @@ module Racc end def next_token - raise NotImplementedError, "#{self.type}\#next_token is not defined" + raise NotImplementedError, "#{self.class}\#next_token is not defined" end def _racc_do_parse_rb( arg, in_debug ) @@ -467,12 +467,12 @@ nerr = 0 # tmp end def racc_token2str( tok ) - type::Racc_token_to_s_table[tok] or + self.class::Racc_token_to_s_table[tok] or raise RuntimeError, "[Racc Bug] can't convert token #{tok} to string" end def token_to_str( t ) - type::Racc_token_to_s_table[t] + self.class::Racc_token_to_s_table[t] end end diff --git a/lib/resolv.rb b/lib/resolv.rb index 14ced1217e..a29d8de27f 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -1239,11 +1239,11 @@ class Resolv class Query def encode_rdata(msg) - raise EncodeError.new("#{self.type} is query.") + raise EncodeError.new("#{self.class} is query.") end def self.decode_rdata(msg) - raise DecodeError.new("#{self.type} is query.") + raise DecodeError.new("#{self.class} is query.") end end @@ -1259,7 +1259,7 @@ class Resolv end def ==(other) - return self.type == other.type && + return self.class == other.class && self.instance_variables == other.instance_variables && self.instance_variables.collect {|name| self.instance_eval name} == other.instance_variables.collect {|name| other.instance_eval name} diff --git a/lib/set.rb b/lib/set.rb index 04c7b101fa..945bdd7c98 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -226,7 +226,7 @@ class Set def dup myhash = @hash - type.new.instance_eval { + self.class.new.instance_eval { @hash.replace(myhash) self } @@ -247,7 +247,7 @@ class Set end def replace(enum) - if enum.type == type + if enum.class == self.class @hash.replace(enum.instance_eval { @hash }) else enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable" @@ -282,7 +282,7 @@ class Set protected :flatten_merge def flatten - type.new.flatten_merge(self) + self.class.new.flatten_merge(self) end def flatten! @@ -340,7 +340,7 @@ class Set end def collect! - set = type.new + set = self.class.new each { |o| set << yield(o) } replace(set) end @@ -353,7 +353,7 @@ class Set end def merge(enum) - if enum.type == type + if enum.class == self.class @hash.update(enum.instance_eval { @hash }) else enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable" @@ -382,7 +382,7 @@ class Set def &(enum) enum.is_a?(Enumerable) or raise ArgumentError, "value must be enumerable" - n = type.new + n = self.class.new enum.each { |o| include?(o) and n.add(o) } n end @@ -415,7 +415,7 @@ class Set each { |i| x = yield(i) - (h[x] ||= type.new).add(i) + (h[x] ||= self.class.new).add(i) } h @@ -441,7 +441,7 @@ class Set set = Set.new() dig.each_strongly_connected_component { |css| - set.add(type.new(css)) + set.add(self.class.new(css)) } set else @@ -455,19 +455,19 @@ class Set ids = (Thread.current[InspectKey] ||= []) if ids.include?(id) - return sprintf('#<%s: {...}>', type.name) + return sprintf('#<%s: {...}>', self.class.name) end begin ids << id - return sprintf('#<%s: {%s}>', type, to_a.inspect[1..-2]) + return sprintf('#<%s: {%s}>', self.class, to_a.inspect[1..-2]) ensure ids.pop end end def pretty_print(pp) - pp.text sprintf('#<%s: {', type.name) + pp.text sprintf('#<%s: {', self.class.name) pp.nest(1) { first = true each { |o| @@ -484,7 +484,7 @@ class Set end def pretty_print_cycle(pp) - pp.text sprintf('#<%s: {%s}>', type.name, empty? ? '' : '...') + pp.text sprintf('#<%s: {%s}>', self.class.name, empty? ? '' : '...') end end diff --git a/lib/shell/command-processor.rb b/lib/shell/command-processor.rb index 459cf858d0..79310359e6 100644 --- a/lib/shell/command-processor.rb +++ b/lib/shell/command-processor.rb @@ -49,7 +49,7 @@ class Shell rescue LoadError, Errno::ENOENT rescue print "load error: #{rc}\n" - print $!.type, ": ", $!, "\n" + print $!.class, ": ", $!, "\n" for err in $@[0, $@.size - 2] print "\t", err, "\n" end @@ -277,7 +277,7 @@ class Shell when IO AppendIO.new(@shell, to, filter) else - Shell.Fail CanNotMethodApply, "append", to.type + Shell.Fail CanNotMethodApply, "append", to.class end end diff --git a/lib/shell/filter.rb b/lib/shell/filter.rb index 441cded221..727826b7c9 100644 --- a/lib/shell/filter.rb +++ b/lib/shell/filter.rb @@ -47,7 +47,7 @@ class Shell self.input = src self else - Filter.Fail CanNotMethodApply, "<", to.type + Filter.Fail CanNotMethodApply, "<", to.class end end @@ -63,7 +63,7 @@ class Shell when IO each(){|l| to << l} else - Filter.Fail CanNotMethodApply, ">", to.type + Filter.Fail CanNotMethodApply, ">", to.class end self end @@ -72,7 +72,7 @@ class Shell begin Shell.cd(@shell.pwd).append(to, self) rescue CanNotMethodApply - Shell.Fail CanNotMethodApply, ">>", to.type + Shell.Fail CanNotMethodApply, ">>", to.class end end diff --git a/lib/shell/system-command.rb b/lib/shell/system-command.rb index c22b9ac0a4..6071c1c841 100644 --- a/lib/shell/system-command.rb +++ b/lib/shell/system-command.rb @@ -15,8 +15,8 @@ require "shell/filter" class Shell class SystemCommand < Filter def initialize(sh, command, *opts) - if t = opts.find{|opt| !opt.kind_of?(String) && opt.type} - Shell.Fail TypeError, t.type, "String" + if t = opts.find{|opt| !opt.kind_of?(String) && opt.class} + Shell.Fail TypeError, t.class, "String" end super(sh) @command = command diff --git a/lib/singleton.rb b/lib/singleton.rb index d34853702f..3c20c13253 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -76,7 +76,7 @@ module Singleton def included(klass) # remove build in copying methods klass.class_eval do - define_method(:clone) {raise TypeError, "can't clone singleton #{self.type}"} + define_method(:clone) {raise TypeError, "can't clone singleton #{self.class}"} end # initialize the ``klass instance variable'' @__instance__ to nil @@ -200,7 +200,7 @@ Thread.abort_on_exception = false class Ups < SomeSingletonClass def initialize - type.__sleep + self.class.__sleep puts "initialize called by thread ##{Thread.current[:i]}" end class << self diff --git a/lib/tracer.rb b/lib/tracer.rb index 6ff9caa98c..70be58da5a 100644 --- a/lib/tracer.rb +++ b/lib/tracer.rb @@ -62,9 +62,7 @@ class Tracer off end else - set_trace_func proc{|event, file, line, id, binding, klass, *rest| - trace_func event, file, line, id, binding, klass - } + set_trace_func method(:trace_func).to_proc stdout.print "Trace on\n" if Tracer.verbose? end end @@ -114,7 +112,7 @@ class Tracer end end - def trace_func(event, file, line, id, binding, klass) + def trace_func(event, file, line, id, binding, klass, *) return if file == MY_FILE_NAME for p in @filters diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index 775a001392..5071c1af93 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -36,7 +36,7 @@ Object end def default_port - self.type.default_port + self.class.default_port end =begin @@ -121,7 +121,7 @@ Object end else raise ArgumentError, - "expected Array of or Hash of components of #{self.type} (#{self.type.component.join(', ')})" + "expected Array of or Hash of components of #{self.class} (#{self.class.component.join(', ')})" end tmp << true @@ -195,7 +195,7 @@ Object =end def component - self.type.component + self.class.component end # set_XXX method sets value to @XXX instance variable with no check, @@ -1087,7 +1087,7 @@ Object =begin =end def inspect - sprintf("#<%s:0x%x URL:%s>", self.type.to_s, self.id, self.to_s) + sprintf("#<%s:0x%x URL:%s>", self.class.to_s, self.id, self.to_s) end =begin