Skip to content
/ arity Public

logic to determine when Ruby functions can be called

License

Notifications You must be signed in to change notification settings

fledman/arity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arity

Logic to determine when Ruby functions can be called.

Installation

Add gem 'arity' to your Gemfile.

Usage

function = Arity::Function.make(some_callable)
# note the use of .make versus .new
# some_callable should respond to :call
# otherwise, .make will raise an Arity::NotCallableError
# to avoid raising, pass {silent: true} to .make and it will return nil instead
function.arity
# delegates to Ruby's built-in arity logic
function.takes?(arg_count: 3, keywords: [:things])
# determines if the supplied method parameter structure is valid.
function.runnable?('thing-1','thing-2','thing-3', things: 3)
# computes the parameter structure and delegates to .takes?
function.run('thing-1','thing-2','thing-3', things: 3)
# calls .call on the callable with the supplied parameters

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fledman/arity.

License

The gem is available as open source under the terms of the MIT License.

About

logic to determine when Ruby functions can be called

Resources

License

Stars

Watchers

Forks

Packages

No packages published