Sha256: 5de81413708dbaf56ef31562183ba084ff6a8a7002ced1be95e68a29a8b60111

Contents?: true

Size: 908 Bytes

Versions: 28

Compression:

Stored size: 908 Bytes

Contents

module Backports
  # Modified to avoid polluting Module if so desired
  # (from Rails)
  def self.alias_method_chain(mod, target, feature)
    mod.class_eval do
      # Strip out punctuation on predicates or bang methods since
      # e.g. target?_without_feature is not a valid method name.
      aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
      yield(aliased_target, punctuation) if block_given?

      with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"

      alias_method without_method, target
      alias_method target, with_method

      case
      when public_method_defined?(without_method)
        public target
      when protected_method_defined?(without_method)
        protected target
      when private_method_defined?(without_method)
        private target
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
backports-3.25.0 lib/backports/tools/alias_method_chain.rb
backports-3.24.1 lib/backports/tools/alias_method_chain.rb
backports-3.24.0 lib/backports/tools/alias_method_chain.rb
backports-3.23.0 lib/backports/tools/alias_method_chain.rb
backports-3.22.1 lib/backports/tools/alias_method_chain.rb
backports-3.22.0 lib/backports/tools/alias_method_chain.rb
backports-3.21.0 lib/backports/tools/alias_method_chain.rb
backports-3.20.2 lib/backports/tools/alias_method_chain.rb
backports-3.20.1 lib/backports/tools/alias_method_chain.rb
backports-3.20.0 lib/backports/tools/alias_method_chain.rb
backports-3.19.0 lib/backports/tools/alias_method_chain.rb
backports-3.18.2 lib/backports/tools/alias_method_chain.rb
backports-3.18.1 lib/backports/tools/alias_method_chain.rb
backports-3.18.0 lib/backports/tools/alias_method_chain.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/backports-3.12.0/lib/backports/tools/alias_method_chain.rb
backports-3.17.2 lib/backports/tools/alias_method_chain.rb
backports-3.17.1 lib/backports/tools/alias_method_chain.rb
backports-3.17.0 lib/backports/tools/alias_method_chain.rb
backports-3.16.1 lib/backports/tools/alias_method_chain.rb
backports-3.16.0 lib/backports/tools/alias_method_chain.rb