File: pry.rb

package info (click to toggle)
ruby-ae 1.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 208 kB
  • sloc: ruby: 936; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'ae/basic_object'

module Kernel

  # TODO: Is th cache really neccessry?

  #
  $PRY_TABLE = {}

  # Pry allows you to test private and protected methods
  # thru a public-only interface.
  #
  # Generally one should avoid testing private and protected
  # methods directly, instead relying on tests of public methods to
  # indirectly test them, because private and protected methods are
  # considered implementation details. But sometimes it is necessary
  # to test them directly, or if you wish to achieve *absolute
  # coverage*, say in a mission critical system.
  #
  # @return [Pry] pry functor
  def pry
    $PRY_TABLE[self] ||= Pry.new do |op, *a, &b|
      __send__(op, *a, &b)
    end
  end

  # Pry Functor
  class Pry < AE::BasicObject
    #instance_methods.each{ |m| private m unless m.to_s =~ /^__/ }
    def initialize(&function)
      @function = function
    end
    def method_missing(op, *a, &b)
      @function.call(op, *a, &b)
    end
  end

end