Skip to content

Instantly share code, notes, and snippets.

@zdennis
Last active June 13, 2019 14:12
Show Gist options
  • Save zdennis/edcc6721146ac85da4f3295a28530748 to your computer and use it in GitHub Desktop.
Save zdennis/edcc6721146ac85da4f3295a28530748 to your computer and use it in GitHub Desktop.
aliasing methods stack level too deep issue when a module is included more than once
module M
def self.included(base)
base.class_eval do
alias_method :user_without_name, :user
alias_method :user, :user_with_name
end
end
def user
puts "in user"
end
def user_with_name
puts "in user_with_name"
user_without_name || "foo"
end
end
class A
include M
end
A.new.user
A.class_eval { include M }
A.new.user # stack-level too deep
module M
def self.included(base)
base.class_eval do
def user
puts "in user"
end
def user_with_name
puts "in user_with_name"
user_without_name || "foo"
end
alias_method :user_without_name, :user
alias_method :user, :user_with_name
end
end
end
class A
include M
end
A.new.user
A.class_eval { include M }
A.new.user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment