From 364cd8679d5a81e3fe3c108f0bf2ab87352ab313 Mon Sep 17 00:00:00 2001 From: barseek Date: Tue, 2 Jul 2024 01:34:56 +0200 Subject: [PATCH] grab --- lib/phlex/helpers.rb | 8 ++++++++ quickdraw/helpers/grap.test.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 quickdraw/helpers/grap.test.rb diff --git a/lib/phlex/helpers.rb b/lib/phlex/helpers.rb index 1bfbaf83..e1533ed2 100644 --- a/lib/phlex/helpers.rb +++ b/lib/phlex/helpers.rb @@ -42,4 +42,12 @@ def mix(*args) end end end + + def grab(**bindings) + if bindings.size > 1 + bindings.values + else + bindings.values.first + end + end end diff --git a/quickdraw/helpers/grap.test.rb b/quickdraw/helpers/grap.test.rb new file mode 100644 index 00000000..69451114 --- /dev/null +++ b/quickdraw/helpers/grap.test.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +include Phlex::Helpers + +test "supports many bindings" do + output = grab({ class: "foo" }, { if: "bar" }) + expect(output) == ["foo", "bar"] +end + +test "supports single binding" do + output = grab({ class: "foo" }) + expect(output) == ["foo"] +end