Module: Tins::Responding

Included in:
Object
Defined in:
lib/tins/responding.rb

Instance Method Summary collapse

Instance Method Details

#responding?(*method_names) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tins/responding.rb', line 3

def responding?(*method_names)
  Class.new do
    define_method(:to_s) do
      "Responding to #{method_names * ', '}"
    end

    alias inspect to_s

    define_method(:===) do |object|
      method_names.all? do |method_name|
        object.respond_to?(method_name)
      end
    end
  end.new
end