Skip to content

Instantly share code, notes, and snippets.

@Marahin
Forked from tuxfight3r/heredoc_erb1.rb
Created August 30, 2019 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marahin/aef7e934953abb7914af87706f76e677 to your computer and use it in GitHub Desktop.
Save Marahin/aef7e934953abb7914af87706f76e677 to your computer and use it in GitHub Desktop.
ruby DATA and __END__ heredoc method
#!/usr/bin/ruby
DATA.each_line do |line|
puts line
end
__END__
Doom
Quake
Diablo
#!/usr/bin/ruby
require 'erb'
time = Time.now
renderer = ERB.new(DATA.read)
puts renderer.result()
__END__
The current time is <%= time %>.
#!/usr/bin/ruby
DATA.rewind
puts DATA.read # prints the entire source file
__END__
meh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment