tags:

views:

28

answers:

1

I wrote a ruby file which can be used as a library. But in order to test it, I also write some test data.

For example:

class Checker
  do some thing
end

# if this file is used as a library, I don't want following code executed    
checker = Checker.new
checker.dosomething

I know there is a way to determine if the file is used as library or not, but I don't remember it now. It is like:

if ???=__FILE__
  checker = Checker.new
  checker.dosomething
end

Somebody knows? Thanks in advance

+3  A: 

Perhaps what you had in mind was $0 == __FILE__?

Though somebody else will have to confirm if this works in all situations.

Shtééf
@Shteef, yes, it is! Thanks:)
Freewind
@Freewind: if this answers your question, don't forget to click on the tick to indicate that.
Andrew Grimm
@Shteef, I'm not forget :)
Freewind