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 ajsh...@gmail.com for pointing out the Ruby 1.9 problems and working toward a solution. Reviewed-by: Nick Lewis <n...@puppetlabs.com> Signed-off-by: Matt Robinson <m...@puppetlabs.com> --- Local-branch: ticket/2.7.x/7291-ruby19-fixes lib/puppet/interface/action_builder.rb | 4 ++-- lib/puppet/interface/option_builder.rb | 4 ++-- lib/puppet/network/client.rb | 2 +- lib/puppet/network/format.rb | 2 +- lib/puppet/util/selinux.rb | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/interface/action_builder.rb index 62db8de..4948f5f 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 8f358c2..5676ec9 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 diff --git a/lib/puppet/network/client.rb b/lib/puppet/network/client.rb index cd88b9d..c56b213 100644 --- a/lib/puppet/network/client.rb +++ b/lib/puppet/network/client.rb @@ -23,7 +23,7 @@ class Net::HTTP # JJM: This is a "backport" of sorts to older ruby versions which # do not have this accessor. See #896 for more information. - attr_accessor :enable_post_connection_check unless Net::HTTP.instance_methods.include? "enable_post_connection_check" + attr_accessor :enable_post_connection_check unless Net::HTTP.method_defined? "enable_post_connection_check" end # The base class for all of the clients. Many clients just directly diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb index 9cd6cf0..69895c3 100644 --- a/lib/puppet/network/format.rb +++ b/lib/puppet/network/format.rb @@ -106,6 +106,6 @@ class Puppet::Network::Format method = send(name) - return(type == :class ? klass.respond_to?(method) : klass.instance_methods.include?(method)) + return(type == :class ? klass.respond_to?(method) : klass.method_defined?(method)) end end diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index cec8a57..255388d 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -140,7 +140,7 @@ module Puppet::Util::SELinux def read_mounts mounts = "" begin - if File.instance_methods.include? "read_nonblock" + if File.method_defined? "read_nonblock" # If possible we use read_nonblock in a loop rather than read to work- # a linux kernel bug. See ticket #1963 for details. mountfh = File.open("/proc/mounts") -- 1.7.3.1 -- 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.