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.

Signed-off-by: Alex Sharp <[email protected]>
---
Local-branch: ticket/2.7.x/7291
 lib/puppet.rb                     |    1 +
 lib/puppet/core_ext.rb            |    1 +
 lib/puppet/core_ext/symbol.rb     |    7 +++++++
 spec/unit/core_ext/symbol_spec.rb |    8 ++++++++
 4 files changed, 17 insertions(+), 0 deletions(-)
 create mode 100644 lib/puppet/core_ext.rb
 create mode 100644 lib/puppet/core_ext/symbol.rb
 create mode 100644 spec/unit/core_ext/symbol_spec.rb

diff --git a/lib/puppet.rb b/lib/puppet.rb
index e20874b..e69bdb9 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -149,6 +149,7 @@ module Puppet
   end
 end
 
+require 'puppet/core_ext'
 require 'puppet/type'
 require 'puppet/parser'
 require 'puppet/resource'
diff --git a/lib/puppet/core_ext.rb b/lib/puppet/core_ext.rb
new file mode 100644
index 0000000..9bc08e6
--- /dev/null
+++ b/lib/puppet/core_ext.rb
@@ -0,0 +1 @@
+require 'puppet/core_ext/symbol'
\ No newline at end of file
diff --git a/lib/puppet/core_ext/symbol.rb b/lib/puppet/core_ext/symbol.rb
new file mode 100644
index 0000000..32e8a60
--- /dev/null
+++ b/lib/puppet/core_ext/symbol.rb
@@ -0,0 +1,7 @@
+class Symbol
+  if RUBY_VERSION =~ /1\.9*/
+    def sub(*args)
+      self.to_s.sub(*args).to_sym
+    end
+  end
+end
\ No newline at end of file
diff --git a/spec/unit/core_ext/symbol_spec.rb 
b/spec/unit/core_ext/symbol_spec.rb
new file mode 100644
index 0000000..baf85a5
--- /dev/null
+++ b/spec/unit/core_ext/symbol_spec.rb
@@ -0,0 +1,8 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+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