Skip to content

Instantly share code, notes, and snippets.

@scudco
Created November 14, 2008 18:50
Show Gist options
  • Save scudco/25045 to your computer and use it in GitHub Desktop.
Save scudco/25045 to your computer and use it in GitHub Desktop.
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