diff --git a/.circleci/config.yml b/.circleci/config.yml index 1dcb21b..db71747 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -86,6 +86,12 @@ workflows: - test: name: 'ruby 2.6' ruby-version: "2.6" + - test: + name: 'ruby 2.7' + ruby-version: "2.7" + - test: + name: 'ruby 3.0' + ruby-version: "3.0" - publish: filters: branches: diff --git a/lib/safe_values/version.rb b/lib/safe_values/version.rb index 9208bd9..eab65bd 100644 --- a/lib/safe_values/version.rb +++ b/lib/safe_values/version.rb @@ -1,3 +1,3 @@ module SafeValues - VERSION = "1.0.1" + VERSION = "1.0.2" end diff --git a/lib/value.rb b/lib/value.rb index 420fc9a..6af177c 100644 --- a/lib/value.rb +++ b/lib/value.rb @@ -120,8 +120,8 @@ def with(#{params.join(", ")}) end end - def with(hash = {}) - return self if hash.empty? - self.class.with(to_h.merge(hash)) + def with(**kwargs) + return self if kwargs.empty? + self.class.with(**to_h.merge(kwargs)) end end diff --git a/spec/unit/value_spec.rb b/spec/unit/value_spec.rb index 123a4fd..7c8995d 100644 --- a/spec/unit/value_spec.rb +++ b/spec/unit/value_spec.rb @@ -46,6 +46,12 @@ v.a = 10 expect(v.a).to eq(10) end + + it "can update values via .with" do + v = value.new(1, 2).with(a: 10) + expect(v.a).to eq(10) + expect(v.b).to eq(2) + end end context "with optional arguments" do @@ -67,6 +73,14 @@ expect(v.d).to eq(40) end + it "can update values via .with" do + v = value.new(10, 20, 30, 40).with(a: 11, c: 31) + expect(v.a).to eq(11) + expect(v.b).to eq(20) + expect(v.c).to eq(31) + expect(v.d).to eq(40) + end + it "raises an error unless all required positional arguments are provided" do expect { value.new(1) }.to raise_error(ArgumentError, /wrong number of arguments/) end