allomov
3/29/2011 - 8:53 PM

gistfile1.rb

class Foo
    def initialize(*args)
        puts "Initializing Foo"
    end
end
        => nil

def Foo(*args, &block)
    puts args.inspect
    block.call if block
    Class.new(Foo).instance_eval <<-END
            def initialize
    # I'm going to do something with block and args here
                puts "Double surprise!"
            end
            self
        END
end
        => nil

class Bar < Foo("Hi there!") {
        puts "Surprise!"
    }
end
        ["Hi there!"]
        Surprise!
        => nil

Bar.new
        Initializing Foo
        => #<Bar:0x2f776b0>