"Yukihiro Matsumoto" <matz / ruby-lang.org> wrote in message news:1053047645.721520.9976.nullmailer / picachu.netlab.jp...
> Hi,
>
> In message "Re: RCR: $INCLUDED global var"
>     on 03/05/16, ahoward <ahoward / fsl.noaa.gov> writes:
>
> |__LIB__ ?
> |
> |  __LIB__ -> __FILE__ != $0, eg. we have been included.
>
> "include" is the C term, we use "require".  Anyway, I think the
> condition should be reversed, since we check that way.
>
> In message "Re: RCR: $INCLUDED global var"
>     on 03/05/16, Joel VanderWerf <vjoel / PATH.Berkeley.EDU> writes:
>
> |What about
> |
> |   MAIN {
> |     # ...
> |   }
> |
> |It's sorta analogous with BEGIN and END.
>
> Better.  But I still want better name.
>
> matz.
>


Seems like the form of Joel's submission was very close.
Something like ... ?

 DEMO {
   # ...
 }

Could it return true/false for Nobu ... ?

 unless DEMO {}

.... with or without a block.

The way I use it is to DEMOnstrate what the lib can do.
DEMO is informal, but not as informal as 'if __FILE__ == $0'
and more formal IMHO than, for example, 'chomp' ;-))

Better suggestions will, hopefully, follow.


# <code>

$R = true
def dEMO      #  pseudo-DEMO block
  if $R       #  simulate __FILE__ != $0 (i.e. here due to 'require')
    false
  else
    yield if block_given?
    true
  end
end           #  DEMO block returns true or false ONLY
######################################

2.times do
  $R = !$R  #  reverse condition
  if $R
    puts "__FILE__ != $0 (i.e. by require 'xxxxx')"
  else
    puts '__FILE__ == $0 (i.e. NOT by require)'
  end
  puts

#---------  Simulating this code in either condition

          print "DEMO = ", dEMO {}, "\n"

          dEMO do
            #  pseudo-DEMO block
            #  require 'xxxxx'
               puts 'Only run if NOT require-d'
          end

          puts "Run if by require 'xxxxx'" unless dEMO {p '... more DEMO'}

          unless dEMO
            puts 'This is the Real Thing'
          end

#---------


  puts '', '-' * 50, ''
end

# </code>



# <Output>

__FILE__ == $0 (i.e. NOT by require)

DEMO = true
Only run if NOT require-d
"... more DEMO"

--------------------------------------------------

__FILE__ != $0 (i.e. by require 'xxxxx')

DEMO = false
Run if by require 'xxxxx'
This is the Real Thing

--------------------------------------------------

# </Output>


daz