Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marian13/9c25041f835564e945d978839097d419 to your computer and use it in GitHub Desktop.
Save marian13/9c25041f835564e945d978839097d419 to your computer and use it in GitHub Desktop.

Module#include has incompatibilities between Ruby 2 and 3

Try to run the following example:

puts RUBY_VERSION

module IncludeModule
  def foo
    "foo from `IncludeModule`"
  end
end

module PrependModule
  def foo
    super
  end
end

class Service
  prepend PrependModule
end

service = Service.new

service.foo

Service.include IncludeModule

service.foo

Ruby 2 behaviour

Screenshot 2022-10-03 at 00 59 29

Screenshot 2022-10-03 at 00 59 42

Ruby 3 behaviour

Screenshot 2022-10-03 at 01 01 15

Screenshot 2022-10-03 at 01 01 27

More info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment