Ruby Arguments

Ruby

Gem Version Gem Downloads GitHub repo size GitHub Actions CI Ruby Style Guide Coverage Status yard docs License: MIT

Ruby Arguments encapsulate method positional arguments (args), keyword arguments (kwargs), and an optional block (block) in a single value object (null object is also available).

That may be useful for DSLs, caches, callbacks, custom RSpec matchers, hash keys, pattern matching and so on.

The initial Ruby Arguments implementation was extracted from the Convenient Service.

TL;DR

require "ruby_arguments"

def some_method(*args, **kwargs, &block)
  RubyArguments.new(*args, **kwargs, &block)
end

##
# Or shorter from Ruby 2.7.
#
def some_method(...)
  RubyArguments.new(...)
end

args = [:foo, :bar]
kwargs = {foo: :bar, baz: :qux}
block = proc { :foo }

arguments = some_method(*args, **kwargs, &block)

arguments.args
# => [:foo, :bar]

arguments.kwargs
# => {foo: :bar, baz: :qux}

arguments.block
# => #<Proc:0x000000012a97fc18>

arguments.null_arguments?
# => false

arguments.any?
# => true

arguments.none?
# => false

arguments.empty?
# => false

arguments.present?
# => true

arguments.blank?
# => false

arguments[0]
# => :foo

arguments[:foo]
# => :bar

def some_other_method
  RubyArguments.null_arguments
end

null_arguments = some_other_method

null_arguments.null_arguments?
# => true

arguments == null_arguments
# => false

arguments.eql?(null_arguments)
# => false

arguments in [args, kwargs, block]
# => true

arguments in args:, kwargs:, :block
# => true

Installation

Bundler

Add the following line to your Gemfile:

gem "ruby_arguments"

And then run:

bundle install

Without Bundler

Execute the command below:

gem install ruby_arguments

Copyright (c) 2025 Marian Kostyk.