Ruby's __END__
I recently used Ruby's __END__
keyword in a client project.
__END__
denotes the end of regular source code in a Ruby file; nothing below it will be executed.
It's essentially a one-line block-commenting device, which is how we used it when trying to recreate a successful pattern borrowed from somewhere else in the project. Instead of toggling between files, we copied beneath __END__
the code we wanted to emulate, started building the new method, and cleaned up before committing.
One benefit of this technique is that any code below __END__
is available via the special filehandle DATA
:
# foo.rb
puts DATA.map(&:upcase)
__END__
'foo'
'bar'
'baz'
$ ruby foo.rb
'FOO'
'BAR'
'BAZ'
Tweet