diff options
| author | Matt Robinson <matt@puppetlabs.com> | 2011-05-16 14:33:58 -0700 |
|---|---|---|
| committer | Matt Robinson <matt@puppetlabs.com> | 2011-05-16 15:13:52 -0700 |
| commit | 48923af0954e93b5e063e4934809779b4f6cf690 (patch) | |
| tree | eddaf0fce8fac23de251f2c9c033d8e65093d776 /lib/puppet | |
| parent | 68065ff4bb09f90ecfc3d7a71197133d78f3eb3d (diff) | |
| download | puppet-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')
| -rw-r--r-- | lib/puppet/interface/action_builder.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/interface/option_builder.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/network/client.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/format.rb | 2 | ||||
| -rw-r--r-- | 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 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 diff --git a/lib/puppet/network/client.rb b/lib/puppet/network/client.rb index cd88b9d84..c56b21393 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 9cd6cf0b5..69895c344 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 cec8a57d9..255388d58 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") |
