Skip to content

Instantly share code, notes, and snippets.

@dmaze
Created July 17, 2018 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmaze/1dff0e3db045157b5fab9dd90437f2b9 to your computer and use it in GitHub Desktop.
Save dmaze/1dff0e3db045157b5fab9dd90437f2b9 to your computer and use it in GitHub Desktop.
#!/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