Class: Module

Inherits:
Object show all
Defined in:
lib/ruby/module.rb

Instance Method Summary collapse

Instance Method Details

#abstract(name, *params) ⇒ void

This method returns an undefined value.

Creates an abstract method

Examples:

class Collection
  abstract :size
  abstract :add, :args => %w(item)
end


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby/module.rb', line 12

def abstract(name, *params)
  if params.last.is_a?(Hash)
    # abstract :method, :args => %w(a b c)
    params = params.last[:args]
  end

  file, line, = Stupidedi.caller

  if params.empty?
    class_eval("      def \#{name}(*args)\n        raise NoMethodError,\n          \"method \\\#{self.class.name}.\#{name} is abstract\"\n      end\n    RUBY\n  else\n    class_eval(<<-RUBY, file, line.to_i - 1)\n      def \#{name}(*args)\n        raise NoMethodError,\n          \"method \\\#{self.class.name}.\#{name}(\#{params.join(', ')}) is abstract\"\n      end\n    RUBY\n  end\nend\n", file, line.to_i - 1)