Module: JunkDrawer::Callable::ClassMethods

Defined in:
lib/junk_drawer/callable.rb

Overview

‘ClassMethods` defines a class level method `call` that delegates to an instance. It also causes an error to be raised if a public instance method is defined with a name other than `call`

Instance Method Summary collapse

Instance Method Details

#call(*args, &block) ⇒ Object



22
23
24
# File 'lib/junk_drawer/callable.rb', line 22

def call(*args, &block)
  new.(*args, &block)
end

#method_added(method_name) ⇒ Object

Raises:



30
31
32
33
34
35
# File 'lib/junk_drawer/callable.rb', line 30

def method_added(method_name)
  return if valid_callable_method?(method_name)

  raise CallableError, "invalid method name #{method_name}, " \
                      'only public method allowed is "call"'
end

#to_procObject



26
27
28
# File 'lib/junk_drawer/callable.rb', line 26

def to_proc
  new.to_proc
end