File: responding.rb

package info (click to toggle)
ruby-tins 1.32.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,248 kB
  • sloc: ruby: 6,659; makefile: 3
file content (19 lines) | stat: -rw-r--r-- 395 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Tins
  module Responding
    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
  end
end