This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
callable-mixin is a Ruby gem providing a Callable module that gives classes a .call class method (instantiate + invoke) and .to_proc for &ClassName shorthand. Zero runtime dependencies. Supports Ruby 2.3+.
bundle exec rspec # run full test suite
bundle exec rspec spec/callable_spec.rb:42 # run single test by line number
bundle exec rake spec # run specs via rake
bundle exec rake multi:spec # test against all supported Ruby versions (requires rbenv)
bundle exec rake changelog # regenerate CHANGELOG.mdThe entire implementation is ~60 lines in a single module:
lib/callable/mixin.rb— CoreCallablemodule withClassMethods(.call,.to_proc) andConstructionErrorlib/callable.rb— Requires version and mixinlib/callable-mixin.rb— Alternate entry point (requirescallable)spec/callable_spec.rb— Comprehensive spec covering parameter variations, block forwarding, error handling, andto_proc
Including Callable in a class triggers self.included, which extends the class with ClassMethods. This adds:
.call(*args, &block)— Forwards args toinitializeviaruby2_keywords, then calls#call(&block)on the instance. Blocks go to#call, notinitialize..to_proc— Returnsmethod(:call).to_procfor&ClassNamesyntax.
- Exact
ArgumentErrorfrominitialize→ wrapped inConstructionError(preserves backtrace) ArgumentErrorsubclasses frominitialize→ propagated unwrapped- Any error from
#call→ propagated unwrapped - Missing
#callinstance method →NotImplementedError
Uses instance_of?(ArgumentError) intentionally (not is_a?) to distinguish constructor arity mismatches from domain errors.
The .call method uses ruby2_keywords (when available) so that hash-style keyword arguments pass through transparently without triggering Ruby 2.7 deprecation warnings or Ruby 3.x argument errors.
- Frozen string literals in all files
- RSpec with
disable_monkey_patching!andexpectsyntax only - No runtime dependencies — gemspec dev deps are rspec and rake only (Gemfile also includes github_changelog_generator)
##style documentation comments in source