Sha256: eb110ad04a0de31ee51522fa828218fe1a1314695b165a1fb220f1c54d63b50b

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

#### Instance and Singleton Methods

This example shows a custom handler that explicates via both kinds of methods.

Here's a class ```Foo``` that has instance methods and singleton methods:
 
```foo.rb```:
```ruby
require 'debug_helper'

class Foo

  def my_array
    %w/foo bar baz/
  end

  def my_hash
    {:a => 0, :b => 1}
  end

  def self.my_array
    %w/bat bam bad/
  end

  def self.my_hash
    {:c => 2, :d => 3}
  end

end
```

Here's its custom debug handler class ```FooHandler```.

```foo_handler.rb```:
```ruby
require 'debug_helper'

class DebugHelper

  class FooHandler < Handler

    def calls_for_instance
      [
          [:my_array],
          [:my_hash],
          [:respond_to?, :your_array],
          [:respond_to?, :your_hash],
      ]
    end

    def calls_for_class
      [
          [:my_array],
          [:my_hash],
          [:respond_to?, :your_array],
          [:respond_to?, :your_hash],
      ]
    end

  end

end
```

Here's a program that uses the custom handler.

```show.rb```:
```ruby
require 'debug_helper'
require_relative 'foo'
require_relative 'foo_handler'

DebugHelper.show(Foo.new, 'My class Foo')
```

The output shows details of the object.

```show.yaml```:
```yaml
---
Foo (message='My class Foo'):
  Foo#my_array:
  - foo
  - bar
  - baz
  Foo#my_hash:
    :a: 0
    :b: 1
  Foo#respond_to?(:your_array): false
  Foo#respond_to?(:your_hash): false
  Foo.my_array:
  - bat
  - bam
  - bad
  Foo.my_hash:
    :c: 2
    :d: 3
  Foo.respond_to?(:your_array): false
  Foo.respond_to?(:your_hash): false
```

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
debug_helper-2.1.0 markdown/readme/classes/custom/both/show.md
debug_helper-2.0.0 markdown/readme/classes/custom/both/show.md