From 8e1723427b114f91daf541230fec36cc037799d2 Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 07:48:46 +0300 Subject: [PATCH] Preserve keyword arguments across option and builder wrappers --- lib/uber/builder.rb | 3 +++ lib/uber/option.rb | 13 +++++++++---- lib/uber/options.rb | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/uber/builder.rb b/lib/uber/builder.rb index ccd5884..7f4007d 100644 --- a/lib/uber/builder.rb +++ b/lib/uber/builder.rb @@ -16,6 +16,8 @@ def call(context, *args) context end + ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true) + def <<(proc) super Uber::Option[proc, instance_exec: true] end @@ -36,6 +38,7 @@ module Build def build!(context, *args) builders.(context, *args) end + ruby2_keywords(:build!) if respond_to?(:ruby2_keywords, true) end end end diff --git a/lib/uber/option.rb b/lib/uber/option.rb index b59450d..bba5a0c 100644 --- a/lib/uber/option.rb +++ b/lib/uber/option.rb @@ -4,13 +4,18 @@ module Uber class Option def self.[](value, options={}) # TODO: instance_exec: true if value.is_a?(Proc) - return ->(context, *args) { context.instance_exec(*args, &value) } if options[:instance_exec] + return value unless options[:instance_exec] + wrapper = ->(context, *args) { context.instance_exec(*args, &value) } + elsif value.is_a?(Uber::Callable) return value + elsif value.is_a?(Symbol) + wrapper = ->(context, *args){ context.send(value, *args) } + else + return ->(*) { value } end - return value if value.is_a?(Uber::Callable) - return ->(context, *args){ context.send(value, *args) } if value.is_a?(Symbol) - ->(*) { value } + wrapper.ruby2_keywords if wrapper.respond_to?(:ruby2_keywords) + wrapper end end end diff --git a/lib/uber/options.rb b/lib/uber/options.rb index fa98b54..df283d0 100644 --- a/lib/uber/options.rb +++ b/lib/uber/options.rb @@ -25,6 +25,8 @@ def eval(key, *args) self[key].(*args) end + ruby2_keywords(:evaluate, :eval) if respond_to?(:ruby2_keywords, true) + private # DEPRECATED! PLEASE USE UBER::OPTION. @@ -46,6 +48,7 @@ def call(context, *args) evaluate_for(context, *args) end + ruby2_keywords(:call) if respond_to?(:ruby2_keywords, true) alias_method :evaluate, :call def dynamic? @@ -88,6 +91,7 @@ def proc!(context, *args) def callable!(context, *args) @value.call(context, *args) end + ruby2_keywords(:evaluate_for, :method!, :proc!, :callable!) if respond_to?(:ruby2_keywords, true) end end end