# http://ruby-doc.org/core-2.4.0/doc/syntax/calling_methods_rdoc.html#label-Hash+to+Keyword+Arguments+Conversion
class Super
attr_reader :shared
# ServiceObject style class-level activation method
def self.run(**args)
new(**args).tap{ |obj| obj.run }
end
def initialize(shared: 'All subclasses see me', **args)
@shared = shared
end
end
class Child < Super
def initialize(special: nil, **args)
super # this reads **args implicitly!
@special = special
end
def run
puts "Shared:#{shared} Special:#{@special}"
end
end
Child.run(special: 2)
# Shared:All subclasses see me Special:2
Child.run(shared: "super", special: 2)
# Shared:super Special:2