summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-05-16 14:33:58 -0700
committerMatt Robinson <matt@puppetlabs.com>2011-05-16 15:13:52 -0700
commit48923af0954e93b5e063e4934809779b4f6cf690 (patch)
treeeddaf0fce8fac23de251f2c9c033d8e65093d776 /lib/puppet/interface
parent68065ff4bb09f90ecfc3d7a71197133d78f3eb3d (diff)
downloadpuppet-48923af0954e93b5e063e4934809779b4f6cf690.tar.gz
puppet-48923af0954e93b5e063e4934809779b4f6cf690.tar.xz
puppet-48923af0954e93b5e063e4934809779b4f6cf690.zip
(#7291) Fix issues with instance_methods in Ruby 1.9
instance_methods in Ruby 1.8.7 returns an array of strings, but returns an array of symbols in 1.9.2. This manifested itself when running the tests because in 1.9.2 we were trying to call sub on a sybmol. The original proposed solution was to monkey patch symbols to have a sub method, but this didn't deal with the real issue of need to check whether a method was defined, and actually made it worse. Turns out that checking for the presence of a method in an array that may contain symbols and may contain strings is better done by just calling method_defined? instead. This patch addresses all the places ack turned up the code doing this include? check instead of directly calling method_defined?. Thanks to Alex Sharp ajsharp@gmail.com for pointing out the Ruby 1.9 problems and working toward a solution. Reviewed-by: Nick Lewis <nick@puppetlabs.com>
Diffstat (limited to 'lib/puppet/interface')
-rw-r--r--lib/puppet/interface/action_builder.rb4
-rw-r--r--lib/puppet/interface/option_builder.rb4
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/interface/action_builder.rb
index 62db8de06..4948f5fab 100644
--- a/lib/puppet/interface/action_builder.rb
+++ b/lib/puppet/interface/action_builder.rb
@@ -49,9 +49,9 @@ 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.chomp('=')
- unless public_instance_methods.include? property
+ unless method_defined? property
# Using eval because the argument handling semantics are less awful than
# when we use the define_method/block version. The later warns on older
# Ruby versions if you pass the wrong number of arguments, but carries
diff --git a/lib/puppet/interface/option_builder.rb b/lib/puppet/interface/option_builder.rb
index 8f358c222..5676ec977 100644
--- a/lib/puppet/interface/option_builder.rb
+++ b/lib/puppet/interface/option_builder.rb
@@ -18,9 +18,9 @@ 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.chomp('=')
- unless private_instance_methods.include? dsl
+ unless private_method_defined? dsl
define_method(dsl) do |value| @option.send(setter, value) end
end
end