Module: Matchete::ClassMethods
- Defined in:
- lib/matchete.rb
Instance Method Summary collapse
- #convert_to_matcher(method_name) ⇒ Object
- #default(method_name) ⇒ Object
- #on(*args, **kwargs) ⇒ Object
- #supporting(*method_names) ⇒ Object
Instance Method Details
#convert_to_matcher(method_name) ⇒ Object
43 44 45 46 47 |
# File 'lib/matchete.rb', line 43 def convert_to_matcher(method_name) define_method(method_name) do |*args, **kwargs| call_overloaded(method_name, args: args, kwargs: kwargs) end end |
#default(method_name) ⇒ Object
30 31 32 33 |
# File 'lib/matchete.rb', line 30 def default(method_name) @default_methods[method_name] = instance_method(method_name) convert_to_matcher method_name end |
#on(*args, **kwargs) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/matchete.rb', line 15 def on(*args, **kwargs) if kwargs.count.zero? *guard_args, method_name = args guard_kwargs = {} else method_name = kwargs[:method] kwargs.delete :method guard_args = args guard_kwargs = kwargs end @methods[method_name] ||= [] @methods[method_name] << [guard_args, guard_kwargs, instance_method(method_name)] convert_to_matcher method_name end |
#supporting(*method_names) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/matchete.rb', line 35 def supporting(*method_names) -> object do method_names.all? do |method_name| object.respond_to? method_name end end end |