Class: BindableBlock::BoundBlock
- Inherits:
-
Proc
- Object
- Proc
- BindableBlock::BoundBlock
- Defined in:
- lib/bindable_block/bound_block.rb
Instance Method Summary collapse
- #binding ⇒ Object
- #bound_location ⇒ Object
- #call(*args, &block) ⇒ Object
- #hash ⇒ Object
-
#initialize(original_block, target, &method) ⇒ BoundBlock
constructor
A new instance of BoundBlock.
- #inspect ⇒ Object (also: #to_s)
- #lambda? ⇒ Boolean
- #parameters ⇒ Object
Constructor Details
#initialize(original_block, target, &method) ⇒ BoundBlock
Returns a new instance of BoundBlock.
5 6 7 8 9 10 11 12 |
# File 'lib/bindable_block/bound_block.rb', line 5 def initialize(original_block, target, &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 self.target = target end |
Instance Method Details
#binding ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bindable_block/bound_block.rb', line 41 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_location ⇒ Object
22 23 24 |
# File 'lib/bindable_block/bound_block.rb', line 22 def bound_location [bound_file.dup, bound_line_number] end |
#call(*args, &block) ⇒ Object
14 15 16 |
# File 'lib/bindable_block/bound_block.rb', line 14 def call(*args, &block) method.call(*align(args), &block) # match args to arity, since instance_method has lambda properties end |
#hash ⇒ Object
35 36 37 38 |
# File 'lib/bindable_block/bound_block.rb', line 35 def hash target_hash = target.hash rescue 0 target_hash ^ original_block.hash end |
#inspect ⇒ Object Also known as: to_s
30 31 32 |
# File 'lib/bindable_block/bound_block.rb', line 30 def inspect original_block.to_s.gsub(/^#<\w*/, "#<#{self.class.name}") end |
#lambda? ⇒ Boolean
18 19 20 |
# File 'lib/bindable_block/bound_block.rb', line 18 def lambda? original_block.lambda? end |
#parameters ⇒ Object
26 27 28 |
# File 'lib/bindable_block/bound_block.rb', line 26 def parameters original_block.parameters end |