Ruby 1.9 removed Symbol#sub, and it's used in various places
in the puppet codebase.

This is a very simple patch that converts the symbol to a
string, performs the #sub on the string and then reconverts
the string back to a symbol. Crude, but it should work. Still,
once the specs are running under 1.9, we should try to find
a non-monkeypatch solution

Signed-off-by: Alex Sharp <[email protected]>
---
Local-branch: ticket/2.7.x/7291
 lib/puppet/util/monkey_patches.rb     |    4 ++++
 spec/unit/util/monkey_patches_spec.rb |    6 ++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/lib/puppet/util/monkey_patches.rb 
b/lib/puppet/util/monkey_patches.rb
index bd954c6..76ad39d 100644
--- a/lib/puppet/util/monkey_patches.rb
+++ b/lib/puppet/util/monkey_patches.rb
@@ -110,4 +110,8 @@ class Symbol
   def to_proc
     Proc.new { |*args| args.shift.__send__(self, *args) }
   end unless method_defined? :to_proc
+
+  def sub(*args)
+    self.to_s.sub(*args).to_sym
+  end unless method_defined? :sub
 end
diff --git a/spec/unit/util/monkey_patches_spec.rb 
b/spec/unit/util/monkey_patches_spec.rb
index 4b609ad..3685a47 100755
--- a/spec/unit/util/monkey_patches_spec.rb
+++ b/spec/unit/util/monkey_patches_spec.rb
@@ -53,3 +53,9 @@ describe "Array#combination" do
     [1,2,3,4].combination(3).to_a.should == [[1, 2, 3], [1, 2, 4], [1, 3, 4], 
[2, 3, 4]]
   end
 end
+
+describe "Symbol#sub" do
+  it "replaces the contents of the matched symbol with replacement string" do
+    :replace_me_bro.sub("bro", "dude").should == :replace_me_dude
+  end
+end
\ No newline at end of file
-- 
1.7.2.3

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to