summaryrefslogtreecommitdiff
path: root/lib/e2mmap1_0.rb
blob: c5797fd573fc597c4c75c4895df12d2a2c5ad03d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
#   e2mmap.rb - 
#   	$Release Version: 1.0$
#   	$Revision: 1.4 $
#   	$Date: 1997/08/18 07:12:12 $
#   	by Keiju ISHITSUKA
#
# --
#
#

module Exception2MessageMapper
  RCS_ID='-$Header: /home/keiju/var/src/var.lib/ruby/RCS/e2mmap.rb,v 1.4 1997/08/18 07:12:12 keiju Exp keiju $-'
  E2MM = Exception2MessageMapper
  
  def E2MM.extend_to(b)
    c = eval("self", b)
    c.extend(self)
    c.bind(b)
  end
  
  def bind(b)
    eval "
  @binding = binding
  E2MM_ErrorMSG = Hash.new
  
  # fail(err, *rest)
  #	err:	例外
  #	rest:	メッセージに渡すパラメータ
  #
  def fail!(*rest)
    super
  end
  
  def fail(err, *rest)
    $! = err.new(sprintf(E2MM_ErrorMSG[err], *rest))
    super()
  end

  public :fail
  # def_exception(c, m)
  #	    c:  exception
  #	    m:  message_form
  #	例外cのメッセージをmとする.
  #
  def def_e2message(c, m)
    E2MM_ErrorMSG[c] = m
  end
  
  # def_exception(c, m)
  #	    c:  exception_name
  #	    m:  message_form
  #	    s:	例外スーパークラス(デフォルト: Exception)
  #	例外名``c''をもつ例外を定義し, そのメッセージをmとする.
  #
  def def_exception(c, m)

    c = c.id2name if c.kind_of?(Fixnum)
    eval \"class \#{c} < Exception
           end
           E2MM_ErrorMSG[\#{c}] = '\#{m}'
           \", @binding
  end
", b
    
  end
  
  E2MM.extend_to(binding)
  def_exception("ErrNotClassOrModule", "Not Class or Module")
end