On Sat, Jun 4, 2011 at 10:17 AM, Yukihiro Matsumoto <matz / ruby-lang.org> wr=
ote:
>
> Issue #4824 has been updated by Yukihiro Matsumoto.
>
>
> I agree providing a method to tell whether it is loaded as a library or i=
s executed as a command is more elegant than '__FILE__ =3D=3D $0', but I am=
 still afraid #executed? can mean multiple ways so that the name can cause =
confusion. =A0We need a better name.

How about main_program?

if main_program?
  puts "Executing main program!"
end

or possibly executed_directly?

if executed_directly?
  puts "This was executed directly by Ruby"
end

someone else suggested directly_executed? which I think is also fine.

Lastly, I think __MAIN__ is reasonable if a method is not to be used,
though it feels a bit too magic for me.