Class: ItsATrap
- Inherits:
- BasicObject
- Defined in:
- lib/gorillib/utils/console.rb
Overview
An inspecting delegator.
Create a trap passing in any object of your choice.
Any time a method is called on the trap, it prints the method name, all its args, and the direct caller.
Instance Method Summary collapse
- #!=(*args, &block) ⇒ Object
- #[email protected](*args, &block) ⇒ Object
-
#==(*args, &block) ⇒ Object
These are defined on BasicObject, delegate them along with the rest BasicObject.instance_methods => [:==, :equal?, :!, :!=, :instance_eval, :instance_exec, :send, :id].
-
#__obj__ ⇒ Object
The proxied object.
- #equal?(*args, &block) ⇒ Boolean
-
#initialize(obj = ::Object.new, show_ret = false) ⇒ ItsATrap
constructor
A new instance of ItsATrap.
-
#inspect ⇒ Object
(also: #pretty_inspect)
We implement to_s and inspect, because otherwise it's annoyingly noisy.
- #instance_eval(*args, &block) ⇒ Object
- #instance_exec(*args, &block) ⇒ Object
- #methods ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(obj = ::Object.new, show_ret = false) ⇒ ItsATrap
Returns a new instance of ItsATrap.
26 27 28 29 30 |
# File 'lib/gorillib/utils/console.rb', line 26 def initialize(obj=::Object.new, show_ret=false) @obj = obj @call_count = 0 @show_ret = show_ret end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
Any time a method is called on the trap, it prints the method name, all its args, and the direct caller.
59 60 61 |
# File 'lib/gorillib/utils/console.rb', line 59 def method_missing(meth, *args, &block) __describe_and_send__(meth, *args, &block) end |
Instance Method Details
#!=(*args, &block) ⇒ Object
49 |
# File 'lib/gorillib/utils/console.rb', line 49 def !=( *args, &block) ; __describe_and_send__(:!=, *args, &block) ; end |
#[email protected](*args, &block) ⇒ Object
48 |
# File 'lib/gorillib/utils/console.rb', line 48 def [email protected]( *args, &block) ; __describe_and_send__(:!, *args, &block) ; end |
#==(*args, &block) ⇒ Object
These are defined on BasicObject, delegate them along with the rest BasicObject.instance_methods => [:==, :equal?, :!, :!=, :instance_eval, :instance_exec, :send, :id]
46 |
# File 'lib/gorillib/utils/console.rb', line 46 def ==( *args, &block) ; __describe_and_send__(:==, *args, &block) ; end |
#__obj__ ⇒ Object
Returns the proxied object.
40 |
# File 'lib/gorillib/utils/console.rb', line 40 def __obj__ ; @obj ; end |
#equal?(*args, &block) ⇒ Boolean
47 |
# File 'lib/gorillib/utils/console.rb', line 47 def equal?(*args, &block) ; __describe_and_send__(:equal?, *args, &block) ; end |
#inspect ⇒ Object Also known as: pretty_inspect
We implement to_s and inspect, because otherwise it's annoyingly noisy. :pretty_inspect makes pry happy.
34 |
# File 'lib/gorillib/utils/console.rb', line 34 def inspect() "~#{@obj.inspect}~" ; end |
#instance_eval(*args, &block) ⇒ Object
50 |
# File 'lib/gorillib/utils/console.rb', line 50 def instance_eval(*args, &block) ; __describe_and_send__(:instance_eval, *args, &block) ; end |
#instance_exec(*args, &block) ⇒ Object
51 |
# File 'lib/gorillib/utils/console.rb', line 51 def instance_exec(*args, &block) ; __describe_and_send__(:instance_exec, *args, &block) ; end |
#methods ⇒ Object
37 |
# File 'lib/gorillib/utils/console.rb', line 37 def methods() @obj.methods ; end |
#to_s ⇒ Object
35 |
# File 'lib/gorillib/utils/console.rb', line 35 def to_s() @obj.to_s ; end |