Created
July 17, 2018 14:01
-
-
Save dmaze/1dff0e3db045157b5fab9dd90437f2b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# With dry-auto_inject 0.4.5, this prints out "a", "b", "c". | |
# With dry-auto_inject 0.4.6, "b" is lost. | |
# If you remove Base#initialize then "b" is still there. | |
require 'dry-auto_inject' | |
class Container | |
extend Dry::Container::Mixin | |
register(:a) { 'a' } | |
register(:b) { 'b' } | |
register(:c) { 'c' } | |
end | |
Import = Dry::AutoInject(Container) | |
class Base | |
include Import[:a, :b] | |
def initialize(**kwargs) | |
super | |
end | |
end | |
class Derived < Base | |
include Import[:b, :c] | |
def dump | |
puts "a: #{a}" | |
puts "b: #{b}" | |
puts "c: #{c}" | |
end | |
end | |
obj = Derived.new | |
obj.dump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment