Class: BasicObject

Defined in:
lib/bindable_block/instance_exec_b.rb

Instance Method Summary collapse

Instance Method Details

#instance_exec_b(*args, argument_block, &instance_block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bindable_block/instance_exec_b.rb', line 4

def instance_exec_b(*args, argument_block, &instance_block)
  if argument_block.nil?
    instance_exec(*args, &instance_block)
  elsif argument_block.respond_to?(:call) && argument_block.respond_to?(:to_proc)
    ::BindableBlock
      .new(self.singleton_class, &instance_block)
      .bind(self)
      .call(*args, &argument_block)
  else
    ::Kernel.raise ::ArgumentError, "Last argument to instance_exec_b must be blocky (respond to #call and #to_proc), or nil"
  end
end