Skip to content

Instantly share code, notes, and snippets.

View vasilakisfil's full-sized avatar

Filippos Vasilakis vasilakisfil

View GitHub Profile
@havenwood
havenwood / arity_range.rb
Last active August 29, 2015 13:56
Ask a method, lambda or proc for the range of arguments it can be called with from minimum to maximum.
module ArityRange
def arity_range
args = parameters.map &:first
req = args.count :req
opt = args.include?(:rest) ? Float::INFINITY : args.count(:opt)
keyreq = args.count :keyreq
keyopt = args.include?(:keyrest) ? Float::INFINITY : args.count(:key)