Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • e2mmap.rb

Class/Module Index [+]

Quicksearch

E2MM

Constants

E2MM
e2mmap.rb - for ruby 1.1
    $Release Version: 2.0$
    $Revision: 1.10 $
    by Keiju ISHITSUKA

Usage:

U1)

class Foo
  extend Exception2MessageMapper
  def_e2message ExistingExceptionClass, "message..."
  def_exception :NewExceptionClass, "message..."[, superclass]
  ...
end

U2)

module Error
  extend Exception2MessageMapper
  def_e2meggage ExistingExceptionClass, "message..."
  def_exception :NewExceptionClass, "message..."[, superclass]
  ...
end
class Foo
  include Error
  ...
end

foo = Foo.new
foo.Fail ....

U3)

module Error
  extend Exception2MessageMapper
  def_e2message ExistingExceptionClass, "message..."
  def_exception :NewExceptionClass, "message..."[, superclass]
  ...
end
class Foo
  extend Exception2MessageMapper
  include Error
  ...
end

Foo.Fail NewExceptionClass, arg...
Foo.Fail ExistingExceptionClass, arg...

Public Class Methods

Fail(klass = E2MM, err = nil, *rest) click to toggle source
Alias for: Raise
Raise(klass = E2MM, err = nil, *rest) click to toggle source

Fail(klass, err, *rest)

klass:  class to define exception under.
err:    exception
rest:   message arguments
 
               # File e2mmap.rb, line 138
def E2MM.Raise(klass = E2MM, err = nil, *rest)
  if form = e2mm_message(klass, err)
    b = $@.nil? ? caller(1) : $@
    #p $@
    #p __FILE__
    b.shift if b[0] =~ /^#{Regexp.quote(__FILE__)}:/
    raise err, sprintf(form, *rest), b
  else
    E2MM.Fail E2MM, ErrNotRegisteredException, err.inspect
  end
end
            
Also aliased as: Fail
def_e2message(k, c, m) click to toggle source

Exception2MessageMapper#def_e2message(k, e, m)

    k:  class to define exception under.
    e:  exception
    m:  message_form
define exception c with message m.
 
               # File e2mmap.rb, line 114
def E2MM.def_e2message(k, c, m)
  E2MM.instance_eval{@MessageMap[[k, c]] = m}
  c
end
            
def_exception(k, n, m, s = StandardError) click to toggle source

Exception2MessageMapper#def_exception(k, n, m, s)

    k:  class to define exception under.
    n:  exception_name
    m:  message_form
    s:  superclass(default: StandardError)
define exception named ``c'' with message m.
 
               # File e2mmap.rb, line 126
def E2MM.def_exception(k, n, m, s = StandardError)
  n = n.id2name if n.kind_of?(Fixnum)
  e = Class.new(s)
  E2MM.instance_eval{@MessageMap[[k, e]] = m}
  k.const_set(n, e)
end
            
e2mm_message(klass, exp) click to toggle source
 
               # File e2mmap.rb, line 153
def E2MM.e2mm_message(klass, exp)
  for c in klass.ancestors
    if mes = @MessageMap[[c,exp]]
      #p mes
      m = klass.instance_eval('"' + mes + '"')
      return m
    end
  end
  nil
end
            
Also aliased as: message
extend_object(cl) click to toggle source
 
               # File e2mmap.rb, line 55
def E2MM.extend_object(cl)
  super
  cl.bind(self) unless cl < E2MM
end
            
message(klass, exp) click to toggle source
Alias for: e2mm_message

Public Instance Methods

Fail(err = nil, *rest) click to toggle source
Alias for: Raise
Raise(err = nil, *rest) click to toggle source

Fail(err, *rest)

err:    exception
rest:   message arguments
 
               # File e2mmap.rb, line 77
def Raise(err = nil, *rest)
  E2MM.Raise(self, err, *rest)
end
            
Also aliased as: Fail, fail
bind(cl) click to toggle source
 
               # File e2mmap.rb, line 60
def bind(cl)
  self.module_eval %Q[
    def Raise(err = nil, *rest)
      Exception2MessageMapper.Raise(self.class, err, *rest)
    end
    alias Fail Raise

    def self.included(mod)
      mod.extend Exception2MessageMapper
    end
  ]
end
            
def_e2message(c, m) click to toggle source

#def_e2message(c, m)

    c:  exception
    m:  message_form
define exception c with message m.
 
               # File e2mmap.rb, line 88
def def_e2message(c, m)
  E2MM.def_e2message(self, c, m)
end
            
def_exception(n, m, s = StandardError) click to toggle source

#def_exception(n, m, s)

    n:  exception_name
    m:  message_form
    s:  superclass(default: StandardError)
define exception named ``c'' with message m.
 
               # File e2mmap.rb, line 98
def def_exception(n, m, s = StandardError)
  E2MM.def_exception(self, n, m, s)
end
            
fail(err = nil, *rest) click to toggle source
Alias for: Raise

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.