Ruby’s secret file
Ruby has a secret input stream hidden in every source file
Ruby has a secret input stream hidden in every source file.
The ruby interpreter stops parsing the source file when it hits the sentinel marker __END__
like this:
puts 'hello Billy'
__END__
Nothing after this line is parsed
#=> hello Billy
But that's not the end of the story. Everything after the __END__
is still available as an inputstream via the predefined constant DATA
. Let's see:
puts DATA.read
__END__
The good ship Bellerophon
#=> The good ship Bellerophon
A little cryptic to be a whole heap of use but perhaps useful for generating default configuration settings perhaps.
Member discussion