class Loom::MethodSignature::MatchSpec
Public Class Methods
builder()
click to toggle source
# File lib/loom/method_signature.rb, line 72 def builder Builder.new end
new( req_args: nil, opt_args: nil, has_rest_args: nil, keyreq_args: nil, key_args: nil, has_keyrest_args: nil, has_block: nil)
click to toggle source
@param req_args [Fixnum] Number of required args, nil for any. @param opt_args [Fixnum] Number of optional args, nil for any. @param has_rest_args [Boolean] 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.
@param keyreq_args [Fixnum] Number of required keyward args, nil
for any.
@param key_args [Fixnum] Number of optional keyward args, nil
for any.
@param has_keyrest_args [Boolean] 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.
@param has_block [Boolean] Whether a block is defined, nil for any.
# 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
Public Instance Methods
match?(method)
click to toggle source
@return [Boolean]
# 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
Private Instance Methods
check_block_args(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 168 def check_block_args(method_sig) return true if @has_block.nil? return method_sig.has_block_args? == @has_block end
check_key_args(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 162 def check_key_args(method_sig) @key_args.nil? || @key_args == method_sig.key_args.size || method_sig.has_keyrest_args? end
check_keyreq_args(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 156 def check_keyreq_args(method_sig) @keyreq_args.nil? || @keyreq_args == method_sig.keyreq_args.size || method_sig.has_keyrest_args? end
check_keyrest(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 152 def check_keyrest(method_sig) @has_keyrest_args.nil? || method_sig.has_keyrest_args? == @has_keyrest_args end
check_keyword_args(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 144 def check_keyword_args(method_sig) return true if @has_keyrest_args return check_keyrest(method_sig) && check_keyreq_args(method_sig) && check_key_args(method_sig); end
check_opt_args(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 140 def check_opt_args(method_sig) @opt_args.nil? || @opt_args == method_sig.opt_args.size end
check_ordered_args(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 120 def check_ordered_args(method_sig) rest = check_rest(method_sig) if rest && method_sig.has_rest_args? Loom.log.debug1(self) { "returning from failed addon look"} return true end return rest && check_req_args(method_sig) && check_opt_args(method_sig); end
check_req_args(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 136 def check_req_args(method_sig) @req_args.nil? || @req_args == method_sig.req_args.size end
check_rest(method_sig)
click to toggle source
# File lib/loom/method_signature.rb, line 132 def check_rest(method_sig) @has_rest_args.nil? || method_sig.has_rest_args? == @has_rest_args end