Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: e2mmap.rb
#
[0] Fix | Delete
# e2mmap.rb - for ruby 1.1
[1] Fix | Delete
# $Release Version: 2.0$
[2] Fix | Delete
# $Revision: 1.10 $
[3] Fix | Delete
# $Date: 1999/02/17 12:33:17 $
[4] Fix | Delete
# by Keiju ISHITSUKA
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
# Usage:
[8] Fix | Delete
#
[9] Fix | Delete
# U1)
[10] Fix | Delete
# class Foo
[11] Fix | Delete
# extend Exception2MessageMapper
[12] Fix | Delete
# def_e2message ExistingExceptionClass, "message..."
[13] Fix | Delete
# def_exception :NewExceptionClass, "message..."[, superclass]
[14] Fix | Delete
# ...
[15] Fix | Delete
# end
[16] Fix | Delete
#
[17] Fix | Delete
# U2)
[18] Fix | Delete
# module Error
[19] Fix | Delete
# extend Exception2MessageMapper
[20] Fix | Delete
# def_e2meggage ExistingExceptionClass, "message..."
[21] Fix | Delete
# def_exception :NewExceptionClass, "message..."[, superclass]
[22] Fix | Delete
# ...
[23] Fix | Delete
# end
[24] Fix | Delete
# class Foo
[25] Fix | Delete
# include Error
[26] Fix | Delete
# ...
[27] Fix | Delete
# end
[28] Fix | Delete
#
[29] Fix | Delete
# foo = Foo.new
[30] Fix | Delete
# foo.Fail ....
[31] Fix | Delete
#
[32] Fix | Delete
# U3)
[33] Fix | Delete
# module Error
[34] Fix | Delete
# extend Exception2MessageMapper
[35] Fix | Delete
# def_e2message ExistingExceptionClass, "message..."
[36] Fix | Delete
# def_exception :NewExceptionClass, "message..."[, superclass]
[37] Fix | Delete
# ...
[38] Fix | Delete
# end
[39] Fix | Delete
# class Foo
[40] Fix | Delete
# extend Exception2MessageMapper
[41] Fix | Delete
# include Error
[42] Fix | Delete
# ...
[43] Fix | Delete
# end
[44] Fix | Delete
#
[45] Fix | Delete
# Foo.Fail NewExceptionClass, arg...
[46] Fix | Delete
# Foo.Fail ExistingExceptionClass, arg...
[47] Fix | Delete
#
[48] Fix | Delete
#
[49] Fix | Delete
fail "Use Ruby 1.1" if VERSION < "1.1"
[50] Fix | Delete
[51] Fix | Delete
module Exception2MessageMapper
[52] Fix | Delete
@RCS_ID='-$Id: e2mmap.rb,v 1.10 1999/02/17 12:33:17 keiju Exp keiju $-'
[53] Fix | Delete
[54] Fix | Delete
E2MM = Exception2MessageMapper
[55] Fix | Delete
[56] Fix | Delete
def E2MM.extend_object(cl)
[57] Fix | Delete
super
[58] Fix | Delete
cl.bind(self) unless cl == E2MM
[59] Fix | Delete
end
[60] Fix | Delete
[61] Fix | Delete
# backward compatibility
[62] Fix | Delete
def E2MM.extend_to(b)
[63] Fix | Delete
c = eval("self", b)
[64] Fix | Delete
c.extend(self)
[65] Fix | Delete
end
[66] Fix | Delete
[67] Fix | Delete
def bind(cl)
[68] Fix | Delete
self.module_eval %[
[69] Fix | Delete
def Raise(err = nil, *rest)
[70] Fix | Delete
Exception2MessageMapper.Raise(self.class, err, *rest)
[71] Fix | Delete
end
[72] Fix | Delete
alias Fail Raise
[73] Fix | Delete
[74] Fix | Delete
def self.included(mod)
[75] Fix | Delete
mod.extend Exception2MessageMapper
[76] Fix | Delete
end
[77] Fix | Delete
]
[78] Fix | Delete
end
[79] Fix | Delete
[80] Fix | Delete
# Fail(err, *rest)
[81] Fix | Delete
# err: exception
[82] Fix | Delete
# rest: message arguments
[83] Fix | Delete
#
[84] Fix | Delete
def Raise(err = nil, *rest)
[85] Fix | Delete
E2MM.Raise(self, err, *rest)
[86] Fix | Delete
end
[87] Fix | Delete
alias Fail Raise
[88] Fix | Delete
[89] Fix | Delete
# backward compatibility
[90] Fix | Delete
alias fail! fail
[91] Fix | Delete
def fail(err = nil, *rest)
[92] Fix | Delete
begin
[93] Fix | Delete
E2MM.Fail(self, err, *rest)
[94] Fix | Delete
rescue E2MM::ErrNotRegisteredException
[95] Fix | Delete
super
[96] Fix | Delete
end
[97] Fix | Delete
end
[98] Fix | Delete
class << self
[99] Fix | Delete
public :fail
[100] Fix | Delete
end
[101] Fix | Delete
[102] Fix | Delete
[103] Fix | Delete
# def_e2message(c, m)
[104] Fix | Delete
# c: exception
[105] Fix | Delete
# m: message_form
[106] Fix | Delete
# define exception c with message m.
[107] Fix | Delete
#
[108] Fix | Delete
def def_e2message(c, m)
[109] Fix | Delete
E2MM.def_e2message(self, c, m)
[110] Fix | Delete
end
[111] Fix | Delete
[112] Fix | Delete
# def_exception(n, m, s)
[113] Fix | Delete
# n: exception_name
[114] Fix | Delete
# m: message_form
[115] Fix | Delete
# s: superclass(default: StandardError)
[116] Fix | Delete
# define exception named ``c'' with message m.
[117] Fix | Delete
#
[118] Fix | Delete
def def_exception(n, m, s = StandardError)
[119] Fix | Delete
E2MM.def_exception(self, n, m, s)
[120] Fix | Delete
end
[121] Fix | Delete
[122] Fix | Delete
#
[123] Fix | Delete
# Private definitions.
[124] Fix | Delete
#
[125] Fix | Delete
# {[class, exp] => message, ...}
[126] Fix | Delete
@MessageMap = {}
[127] Fix | Delete
[128] Fix | Delete
# E2MM.def_exception(k, e, m)
[129] Fix | Delete
# k: class to define exception under.
[130] Fix | Delete
# e: exception
[131] Fix | Delete
# m: message_form
[132] Fix | Delete
# define exception c with message m.
[133] Fix | Delete
#
[134] Fix | Delete
def E2MM.def_e2message(k, c, m)
[135] Fix | Delete
E2MM.instance_eval{@MessageMap[[k, c]] = m}
[136] Fix | Delete
c
[137] Fix | Delete
end
[138] Fix | Delete
[139] Fix | Delete
# E2MM.def_exception(k, n, m, s)
[140] Fix | Delete
# k: class to define exception under.
[141] Fix | Delete
# n: exception_name
[142] Fix | Delete
# m: message_form
[143] Fix | Delete
# s: superclass(default: StandardError)
[144] Fix | Delete
# define exception named ``c'' with message m.
[145] Fix | Delete
#
[146] Fix | Delete
def E2MM.def_exception(k, n, m, s = StandardError)
[147] Fix | Delete
n = n.id2name if n.kind_of?(Fixnum)
[148] Fix | Delete
e = Class.new(s)
[149] Fix | Delete
E2MM.instance_eval{@MessageMap[[k, e]] = m}
[150] Fix | Delete
k.const_set(n, e)
[151] Fix | Delete
end
[152] Fix | Delete
[153] Fix | Delete
# Fail(klass, err, *rest)
[154] Fix | Delete
# klass: class to define exception under.
[155] Fix | Delete
# err: exception
[156] Fix | Delete
# rest: message arguments
[157] Fix | Delete
#
[158] Fix | Delete
def E2MM.Raise(klass = E2MM, err = nil, *rest)
[159] Fix | Delete
if form = e2mm_message(klass, err)
[160] Fix | Delete
$! = err.new(sprintf(form, *rest))
[161] Fix | Delete
$@ = caller(1) if $@.nil?
[162] Fix | Delete
#p $@
[163] Fix | Delete
#p __FILE__
[164] Fix | Delete
$@.shift if $@[0] =~ /^#{Regexp.quote(__FILE__)}:/
[165] Fix | Delete
raise
[166] Fix | Delete
else
[167] Fix | Delete
E2MM.Fail E2MM, ErrNotRegisteredException, err.inspect
[168] Fix | Delete
end
[169] Fix | Delete
end
[170] Fix | Delete
class <<E2MM
[171] Fix | Delete
alias Fail Raise
[172] Fix | Delete
end
[173] Fix | Delete
[174] Fix | Delete
def E2MM.e2mm_message(klass, exp)
[175] Fix | Delete
for c in klass.ancestors
[176] Fix | Delete
if mes = @MessageMap[[c,exp]]
[177] Fix | Delete
#p mes
[178] Fix | Delete
m = klass.instance_eval('"' + mes + '"')
[179] Fix | Delete
return m
[180] Fix | Delete
end
[181] Fix | Delete
end
[182] Fix | Delete
nil
[183] Fix | Delete
end
[184] Fix | Delete
class <<self
[185] Fix | Delete
alias message e2mm_message
[186] Fix | Delete
end
[187] Fix | Delete
[188] Fix | Delete
E2MM.def_exception(E2MM,
[189] Fix | Delete
:ErrNotRegisteredException,
[190] Fix | Delete
"not registerd exception(%s)")
[191] Fix | Delete
end
[192] Fix | Delete
[193] Fix | Delete
[194] Fix | Delete
[195] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function