Class: BindableBlock::BoundBlock

Inherits:
Proc
  • Object
show all
Defined in:
lib/bindable_block/bound_block.rb

Instance Method Summary collapse

Constructor Details

#initialize(original_block, &method) ⇒ BoundBlock

Returns a new instance of BoundBlock.



5
6
7
8
9
10
11
# File 'lib/bindable_block/bound_block.rb', line 5

def initialize(original_block, &method)
  f, ln, *               = caller[2].split(':')
  self.bound_file        = f
  self.bound_line_number = ln.to_i
  self.original_block    = original_block
  self.method            = method
end

Instance Method Details

#bindingObject

Raises:

  • (NotImplementedError)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bindable_block/bound_block.rb', line 35

def binding
  raise NotImplementedError, <<-SADFACE.gsub(/^\s*/, '')
    I legit tried to figure this out, and can't :(

    * Can't just ask, it's private on most objects
    * Can't use `__send__` b/c it's like "the binding at the top of the callstack", which would not be the binding of the obj you're invoking it on
    * Can't `instance_eval { binding }`, because BasicObject doesn't have a binding method
    * Can't `Kernel.instance_method(:binding).bind(obj).instance_eval { binding }` because if obj is a BasicObject, then Kernel isn't an ancestor and thus won't bind to it
    * Tried all manner of adding temp methods, subclassing the singleton class, etc. In the end, I think it's just not doable.

    This is your friendly reminder that whatever you're using this method for is probably bullshit.
  SADFACE
end

#bound_locationObject



21
22
23
# File 'lib/bindable_block/bound_block.rb', line 21

def bound_location
  [bound_file.dup, bound_line_number]
end

#call(*args, &block) ⇒ Object



13
14
15
# File 'lib/bindable_block/bound_block.rb', line 13

def call(*args, &block)
  method.call(*align(args), &block)
end

#inspectObject Also known as: to_s



29
30
31
# File 'lib/bindable_block/bound_block.rb', line 29

def inspect
  original_block.to_s.gsub(/^#<\w*/, "#<#{self.class.name}")
end

#lambda?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/bindable_block/bound_block.rb', line 17

def lambda?
  original_block.lambda?
end

#parametersObject



25
26
27
# File 'lib/bindable_block/bound_block.rb', line 25

def parameters
  original_block.parameters
end