It's just you :-)

---------------------------------------------
matt@linux1 matt $ ruby -v
ruby 1.8.1 (2004-04-24) [i686-linux-gnu]
matt@linux1 matt $ cat moo.rb 

class DelayedInstance
  def initialize(klass, *args, &block)
    @klass  = klass
    @args   = args
    @block  = block
    @object = nil
  end

  def method_missing(sym, *args, &block)
    STDOUT.puts "Inside method missing:  #{sym}"
    @object = @klass.send(:new, *@args, &@block) if @object.nil?
    @object.send(sym, *args, &block)
  end
end

class Test
  def initialize(*args, &block)
    STDOUT.puts "Initializing test: #{args.inspect}"
    @data = args
  end

  def show_data
    STDOUT.puts @data.inspect
  end

  def to_s
    "You don't own space, so stop acting like you do."
  end
end

test = DelayedInstance.new(Test, 1, 2, 3, 4)

p "to_s"
p test.to_s
puts

p "show_data"
p test.show_data

matt@linux1 matt $ ruby moo.rb 
"to_s"
"#<DelayedInstance:0x4028e14c>"

"show_data"
Inside method missing:  show_data
Initializing test: [1, 2, 3, 4]
[1, 2, 3, 4]
nil
---------------------------------------------


Anders Borch <ruby / deck.dk> wrote in message news:<40D17236.8020600 / deck.dk>...
> is it just me, or could the same results come from this:
> 
> class DelayedInstance
>    def initialize(klass,*args)
>      @klass = klass
>      @args = args
>      @object = nil
>    end
> 
>    def method_missing(meth,*args,&block)
>      @object = @klass.send(:new,*@args) if @object.nil?
>      @object.send(meth,*args,&block)
>    end
> end