Class: Loom::MethodSignature::MatchSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/loom/method_signature.rb

Defined Under Namespace

Classes: Builder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(req_args: nil, opt_args: nil, has_rest_args: nil, keyreq_args: nil, key_args: nil, has_keyrest_args: nil, has_block: nil) ⇒ MatchSpec

Returns a new instance of MatchSpec.

Parameters:

  • req_args (Fixnum) (defaults to: nil)

    Number of required args, nil for any.

  • opt_args (Fixnum) (defaults to: nil)

    Number of optional args, nil for any.

  • has_rest_args (Boolean) (defaults to: nil)

    Whether a *args is defined, nil for any. If has_rest_args is true then any number of req or opt args will satisfy this match.

  • keyreq_args (Fixnum) (defaults to: nil)

    Number of required keyward args, nil for any.

  • key_args (Fixnum) (defaults to: nil)

    Number of optional keyward args, nil for any.

  • has_keyrest_args (Boolean) (defaults to: nil)

    Whether a **opts is defined, nil for any. If has_keyrest_args is true, then any number of keyreq or key args will satisfy this match for name named opts.

  • has_block (Boolean) (defaults to: nil)

    Whether a block is defined, nil for any.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/loom/method_signature.rb', line 90

def initialize(
      req_args: nil,
      opt_args: nil,
      has_rest_args: nil,
      keyreq_args: nil,
      key_args: nil,
      has_keyrest_args: nil,
      has_block: nil)
  @req_args = req_args
  @opt_args = opt_args
  @has_rest_args = has_rest_args
  @keyreq_args = keyreq_args
  @key_args = key_args
  @has_keyrest_args = has_keyrest_args
  @has_block = has_block
end

Class Method Details

.builderObject



72
73
74
# File 'lib/loom/method_signature.rb', line 72

def builder
  Builder.new
end

Instance Method Details

#match?(method) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
111
112
113
114
115
116
117
# File 'lib/loom/method_signature.rb', line 108

def match?(method)
  method_sig = MethodSignature.new method

  # *args definition matches any call.
  return true if @has_rest_args

  check_ordered_args(method_sig) &&
    check_keyword_args(method_sig) &&
    check_block_args(method_sig)
end