Created
November 14, 2008 18:50
-
-
Save scudco/25045 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
module ForwardInitialization | |
module ClassMethods | |
def new(*args,&block) | |
# name in this case is very different from self.class.to_s | |
const_get("#{name.split("::").last}").new(*args,&block) | |
end | |
end | |
def self.included(klass) | |
klass.extend(ClassMethods) | |
end | |
end | |
module Foo | |
class Bar | |
def initialize(params={}) | |
yield | |
puts "in Foo::Bar with params: #{params}" | |
end | |
end | |
end | |
module Boo | |
module Baz | |
include ForwardInitialization | |
class Baz < ::Foo::Bar | |
def initialize(params={}) | |
super | |
puts "in Baz::Baz with params: #{params}" | |
end | |
end | |
end | |
end | |
puts Boo::Baz.new(:foo => "foo",:bar => "bar") { puts 'bazbazbaz' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment