Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. module ForwardInitialization
  2. module ClassMethods
  3. def new(*args,&block)
  4. # name in this case is very different from self.class.to_s
  5. const_get("#{name.split("::").last}").new(*args,&block)
  6. end
  7. end
  8.  
  9. def self.included(klass)
  10. klass.extend(ClassMethods)
  11. end
  12. end
  13.  
  14. module Foo
  15. class Bar
  16. def initialize(params={})
  17. yield
  18. puts "in Foo::Bar with params: #{params}"
  19. end
  20. end
  21. end
  22.  
  23. module Boo
  24. module Baz
  25. include ForwardInitialization
  26.  
  27. class Baz < ::Foo::Bar
  28. def initialize(params={})
  29. super
  30. puts "in Baz::Baz with params: #{params}"
  31. end
  32. end
  33. end
  34. end
  35.  
  36.  
  37. puts Boo::Baz.new(:foo => "foo",:bar => "bar") { puts 'bazbazbaz' }
Add Comment
Please, Sign In to add comment