Sha256: d632af7efcef7bfdeda0fc8f47a1987c0638c9140b66e796100263d98d0427c2

Contents?: true

Size: 732 Bytes

Versions: 2

Compression:

Stored size: 732 Bytes

Contents

require "binding_of_callers/version"
require 'binding_of_callers/revealed'
require 'binding_of_caller'

class Binding

  def of_callers(fc = frame_count)
    enhance(fc) do |bi|
      BindingOfCallers::Revealed.new bi
    end
  end

  def of_callers!(fc = frame_count)
    enhance(fc) do |bi|
      bi.extend BindingOfCallers::Reveal
    end
  end

  def partial_callers(limit)
    _callers = callers
    limit = _callers.size + limit if limit < 0
    _callers[1, limit].map!{ |c| BindingOfCallers::Revealed.new(c) }
  end

  private

  def enhance(fc, &enhance)
    collected(fc).map(&enhance)
  end

  def collected(fc)
    n = 3
    bis = []
    while n < fc
      bis << of_caller(n)
      n = n.succ
    end
    bis
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
binding_of_callers-0.2.3 lib/binding_of_callers.rb
binding_of_callers-0.2.2 lib/binding_of_callers.rb