From 16a78e1b5f7e5eec1c2793d9a5a18799b954afc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Fri, 12 Dec 2025 17:54:11 +0100 Subject: [PATCH] Use `clone` instead of creating new objects While `clone` is supposed to create shallow copy, it seems it creates clone for the delegator just fine. This results in simpler and more readable code and most importantly, it will enable custom fields in RpmDependency class. --- lib/gem2rpm/rpm_dependency.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/gem2rpm/rpm_dependency.rb b/lib/gem2rpm/rpm_dependency.rb index 8cfaee6..ed813f8 100644 --- a/lib/gem2rpm/rpm_dependency.rb +++ b/lib/gem2rpm/rpm_dependency.rb @@ -12,31 +12,28 @@ def initialize(dependency) # Convert to rubygem() virtual provide dependency. def virtualize - dep = __getobj__.dup - dep.name = "rubygem(#{dep.name})" - - self.class.new dep + clone.tap do |dep| + dep.name = "rubygem(#{dep.name})" + end end # Output dependency with RPM requires tag. def with_requires - dep = __getobj__.dup - dep.name = case dep.type - when :development - "BuildRequires: #{dep.name}" - else - "Requires: #{dep.name}" + clone.tap do |dep| + dep.name = case dep.type + when :development + "BuildRequires: #{dep.name}" + else + "Requires: #{dep.name}" + end end - - self.class.new dep end # Comment out the dependency. def comment_out - dep = __getobj__.dup - dep.name = "# #{dep.name}" - - self.class.new dep + clone.tap do |dep| + dep.name = "# #{dep.name}" + end end # Returns string with entry suitable for RPM .spec file.