From c912583a28558f5af1732579156181c4152b0bde Mon Sep 17 00:00:00 2001 From: Rupayon Haldar <80724680+rupayon123@users.noreply.github.com> Date: Thu, 10 Sep 2026 13:38:39 -0400 Subject: [PATCH] fix: support symbolic chain operators on ruby 2.6 --- lib/rubyshell/chainer.rb | 2 +- lib/rubyshell/command.rb | 2 +- spec/chainer_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/rubyshell/chainer.rb b/lib/rubyshell/chainer.rb index ab32002..3097819 100644 --- a/lib/rubyshell/chainer.rb +++ b/lib/rubyshell/chainer.rb @@ -28,7 +28,7 @@ def settings end def method_missing(method_name, *args, &block) - if method_name.start_with?(/[^A-Za-z0-9]/) + if method_name.to_s.match?(/\A[^A-Za-z0-9]/) handle_chain(method_name, args.first) else super diff --git a/lib/rubyshell/command.rb b/lib/rubyshell/command.rb index fa0f852..3fe3ac2 100644 --- a/lib/rubyshell/command.rb +++ b/lib/rubyshell/command.rb @@ -41,7 +41,7 @@ def parsed_args private def method_missing(method_name, *args, &block) - if method_name.start_with?(/[^A-Za-z0-9]/) + if method_name.to_s.match?(/\A[^A-Za-z0-9]/) RubyShell::Chainer.new(self).send(method_name, *args, block) else super diff --git a/spec/chainer_spec.rb b/spec/chainer_spec.rb index c318d22..ddf8f9d 100644 --- a/spec/chainer_spec.rb +++ b/spec/chainer_spec.rb @@ -10,6 +10,28 @@ end describe "Validating Chains" do + context "when chaining several commands with symbolic pipe operators" do + def subject_call + sh do + (printf!("hello") | cat! | cat!).exec + end + end + + it "executes every command in the pipeline" do + expect(subject_call).to eq("hello") + end + end + + context "when an unknown ordinary method is called on a command" do + def subject_call + RubyShell::Command.new("printf", "hello").unknown_chain_method + end + + it "raises for the requested method instead of operator detection" do + expect { subject_call }.to raise_error(NoMethodError, /unknown_chain_method/) + end + end + context "when counting files in current folder" do def subject_call sh do