Sha256: 75e4cd3655cf9911794eed299bfd0e3a5cc07a2bc64f2adbdd083f43c8295e79

Contents?: true

Size: 723 Bytes

Versions: 13

Compression:

Stored size: 723 Bytes

Contents

# *Correct* `alias_method_chain_once` implementation
class Module
  def alias_method_chain_once(target, feature)
    aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
    without_method = "#{aliased_target}_without_#{feature}#{punctuation}"

    # `method_defined?` matches public and protected methods,
    # also `*_method_defined?` family of methods is the portable
    # way to check for method existence, while `public_methods.include?`
    # will work either on 1.8 or 1.9 (depending on where symbol or string
    # is provided as method name)
    unless method_defined?(without_method) ||
            private_method_defined?(without_method)
      alias_method_chain(target, feature)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dolzenko-0.0.24 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.23 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.22 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.21 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.20 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.19 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.18 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.17 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.16 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.15 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.14 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.13 lib/dolzenko/alias_method_chain_once.rb
dolzenko-0.0.12 lib/dolzenko/alias_method_chain_once.rb