I've included both patches below, with the intention of someone merging in one of the them. The first patch is the Symbol monkeypatch, and the second patch fixes this without a monkey patch to the Symbol class.
PATCH 1 ======= 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 <ajsh...@gmail.com> --- 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 PATCH 2 ======= Ruby 1.9 removed Symbol#sub, so we need to do some string conversions for things to continue to work. Signed-off-by: Alex Sharp <ajsh...@gmail.com> --- Local-branch: ticket/2.7.x/7291 lib/puppet/interface/action_builder.rb | 2 +- lib/puppet/interface/option_builder.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/ interface/action_builder.rb index 62db8de..4c1b9ca 100644 --- a/lib/puppet/interface/action_builder.rb +++ b/lib/puppet/interface/action_builder.rb @@ -49,7 +49,7 @@ class Puppet::Interface::ActionBuilder # Metaprogram the simple DSL from the target class. Puppet::Interface::Action.instance_methods.grep(/=$/).each do | setter| next if setter =~ /^=/ - property = setter.sub(/=$/, '') + property = setter.to_s.sub(/=$/, '').intern unless public_instance_methods.include? property # Using eval because the argument handling semantics are less awful than diff --git a/lib/puppet/interface/option_builder.rb b/lib/puppet/ interface/option_builder.rb index 8f358c2..b02c941 100644 --- a/lib/puppet/interface/option_builder.rb +++ b/lib/puppet/interface/option_builder.rb @@ -18,7 +18,7 @@ class Puppet::Interface::OptionBuilder # Metaprogram the simple DSL from the option class. Puppet::Interface::Option.instance_methods.grep(/=$/).each do | setter| next if setter =~ /^=/ - dsl = setter.sub(/=$/, '') + dsl = setter.to_s.sub(/=$/, '').intern unless private_instance_methods.include? dsl define_method(dsl) do |value| @option.send(setter, value) end On May 10, 2:50 pm, markus <mar...@reality.com> wrote: > > > Yea, you're probably right. FWIW, here's the offending block of code > > > in lib/puppet/interface/option_builder.rb:19: > > > [...] > > > Puppet::Interface::Option.instance_methods.grep(/=$/).each do | > > > setter| > > > next if setter =~ /^=/ > > > dsl = setter.to_s.sub(/=$/, '') > > > Yeah, that looks right to me. :) > > You might want to intern it (since it was originally a symbol and the > proposed code leaves it as a string): > > dsl = setter.to_s.sub(/=$/, '').intern > > -- Markus > > P.S. I don't think a monkey patch to add Symbol#sub is too bad either, > especially since it future-proofs the code a little bit. -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to puppet-dev@googlegroups.com. To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.