Skip to content

Commit a049dd4

Browse files
committed
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.
1 parent eb4d16a commit a049dd4

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

lib/gem2rpm/rpm_dependency.rb

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,28 @@ def initialize(dependency)
1212

1313
# Convert to rubygem() virtual provide dependency.
1414
def virtualize
15-
dep = __getobj__.dup
16-
dep.name = "rubygem(#{dep.name})"
17-
18-
self.class.new dep
15+
clone.tap do |dep|
16+
dep.name = "rubygem(#{dep.name})"
17+
end
1918
end
2019

2120
# Output dependency with RPM requires tag.
2221
def with_requires
23-
dep = __getobj__.dup
24-
dep.name = case dep.type
25-
when :development
26-
"BuildRequires: #{dep.name}"
27-
else
28-
"Requires: #{dep.name}"
22+
clone.tap do |dep|
23+
dep.name = case dep.type
24+
when :development
25+
"BuildRequires: #{dep.name}"
26+
else
27+
"Requires: #{dep.name}"
28+
end
2929
end
30-
31-
self.class.new dep
3230
end
3331

3432
# Comment out the dependency.
3533
def comment_out
36-
dep = __getobj__.dup
37-
dep.name = "# #{dep.name}"
38-
39-
self.class.new dep
34+
clone.tap do |dep|
35+
dep.name = "# #{dep.name}"
36+
end
4037
end
4138

4239
# Returns string with entry suitable for RPM .spec file.

0 commit comments

Comments
 (0)