module JunkDrawer::Callable::ClassMethods
`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`
Public Instance Methods
call(*args, &block)
click to toggle source
# File lib/junk_drawer/callable.rb, line 24 def call(*args, &block) new.(*args, &block) end
method_added(method_name)
click to toggle source
# File lib/junk_drawer/callable.rb, line 32 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_proc()
click to toggle source
# File lib/junk_drawer/callable.rb, line 28 def to_proc new.to_proc end
Private Instance Methods
valid_callable_method?(method_name)
click to toggle source
# File lib/junk_drawer/callable.rb, line 41 def valid_callable_method?(method_name) method_name == :call || !public_method_defined?(method_name) || method_name.to_s.start_with?('__') end