> On Sun, Apr 21, 2002 at 06:27:04AM +0900, Michael Brailsford wrote:
> 
>The other idea is to provide a predefined entry point for classes.
>Something akin to C++ "int main()" or Java's "public static void
>main(String[] args)".  If this predefined entry point existed in a class
>in the script then after the file has been read the interpreter would
>run the class using that predefined method.  If it didn't exist then
>behavior would be what it is now.  

Like this?

<<<class_runner.rb>>>
class Class
  def class_runner( name=nil )  
    if $0 == caller.first.split(/:/).first
      if name
	module_eval name.to_s
      else	
	proc = Proc.new
	module_eval &proc
      end
    end
  end
end

<<<test_class_runner.rb>>>
require 'class_runner'

class Sample
  def Sample.foo
    puts "FOO!"
  end
  class_runner :foo
end

class Sample2
  def Sample2.bar
    puts "BAR!"
  end
  class_runner { 
    puts "...block..."
    bar 
  }
end



...and then:

~$ ruby test_class_runner.rb
FOO!
...block...
BAR!

  -- Nikodemus