Project

General

Profile

Actions

Bug #12787

closed

Stackoverflow over when alias_method and prepend are used in combination

Added by ethiraj (ethiraj srinivasan) over 7 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:77386]

Description

With Ruby 2.0 Module#prepend was used to overcome the drawbacks of alias_method_chaining. Most of the gems/projects still use alias_method_chain since they support 1.9.3 and with upcoming gems/projects using prepend for the method that is already aliased throws stackoverflow error since the aliased method and prepend method call each other and results in deadlock.

class Netter
 def requester
  puts " I am requester in Netter"
 end
end
class Netter
  def requester_with_alias
    puts "i am in alias"
    requester_without_alias
  end
  alias_method :requester_without_alias, :requester
  alias_method :requester, :requester_with_alias
end
module Prepender
  def requester
    puts "i am in prepend"
    super
  end
end
Netter.prepend(Prepender)

Netter.new.requester

Files

stackoverflow_with_alias_and_prepend (404 Bytes) stackoverflow_with_alias_and_prepend ethiraj (ethiraj srinivasan), 09/24/2016 06:43 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0