Sha256: 49d1b4613b3df7679648d0a6590beedc927e693cd6b7498efb5aae66b5885407

Contents?: true

Size: 1.55 KB

Versions: 20

Compression:

Stored size: 1.55 KB

Contents

##
## $Rev: 1 $
## $Release: 1.0.0 $
## copyright(c) 2006 kuwata-lab.com all rights reserved.
##
##
## helper to define abstract method in Ruby.
##
##
## example1. (shorter notation)
##
##   require 'abstract'
##   class Foo
##     abstract_method 'arg1, arg2=""', :method1, :method2, :method3
##   end
##
##
## example2. (RDoc friendly notation)
##
##   require 'abstract'
##   class Bar
##     # ... method1 description ...
##     def method1(arg1, arg2="")
##       not_implemented
##     end
##
##     # ... method2 description ...
##     def method2(arg1, arg2="")
##       not_implemented
##     end
##   end
##


##
class Module

  ##
  ## define abstract methods
  ##
  def abstract_method args_str, *method_names
    method_names.each do |name|
      module_eval <<-END
        def #{name}(#{args_str})
          mesg = "class \#{self.class.name} must implement abstract method `#{self.name}##{name}()'."
          #mesg = "\#{self.class.name}##{name}() is not implemented."
          err = NotImplementedError.new mesg
          err.set_backtrace caller()
          raise err
        end
      END
    end
  end

end


##
module Kernel

  ##
  ## raise NotImplementedError
  ##
  def not_implemented     #:doc:
    backtrace = caller()
    method_name = (backtrace.shift =~ /`(\w+)'$/) && $1
    mesg = "class #{self.class.name} must implement abstract method '#{method_name}()'."
    #mesg = "#{self.class.name}##{method_name}() is not implemented."
    err = NotImplementedError.new mesg
    err.set_backtrace backtrace
    raise err
  end
  private :not_implemented

end

Version data entries

20 entries across 18 versions & 5 rubygems

Version Path
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/abstract-1.0.0/lib/abstract.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/abstract-1.0.0/lib/abstract.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/abstract-1.0.0/lib/abstract.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/abstract-1.0.0/lib/abstract.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/abstract-1.0.0/lib/abstract.rb
simple-templater-0.0.1.4 gems/gems/abstract-1.0.0/lib/abstract.rb
simple-templater-0.0.1.3 vendor/abstract/lib/abstract.rb
simple-templater-0.2.pre vendor/abstract/lib/abstract.rb
simple-templater-0.0.1.2 vendor/abstract/lib/abstract.rb
simple-templater-0.0.1.1 vendor/abstract/lib/abstract.rb
rango-0.0.6 vendor/abstract/lib/abstract.rb
rango-0.0.6 vendor/simple-templater/vendor/abstract/lib/abstract.rb
rango-0.1.pre vendor/abstract/lib/abstract.rb
rango-0.1.pre vendor/simple-templater/vendor/abstract/lib/abstract.rb
simple-templater-0.0.1 vendor/abstract/lib/abstract.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/abstract-1.0.0/lib/abstract.rb
abstract-1.0.0 lib/abstract.rb
mack-0.8.2 lib/gems/abstract-1.0.0/lib/abstract.rb
mack-0.8.3.1 lib/gems/abstract-1.0.0/lib/abstract.rb
mack-0.8.3 lib/gems/abstract-1.0.0/lib/abstract.rb