jnewland (owner)

Fork Of

Forks

Revisions

gist: 180570 Download_button fork
public
Public Clone URL: git://gist.github.com/180570.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Surround a heredoc with quotes and you can continue the code on the same line:
 
    render :status => 404, :text => <<-'EOH' and return unless setup
article not found<br/>
I, as a server, have failed<br/>
https?
EOH
 
Quotes also give you more freedom/creativity with the terminal ID:
 
    eval <<-"end;"
      def #{foo}
        bar
      end
    end;
 
Also, you can include multiple Heredocs on the same line:
 
    puts <<-"end:foo", <<-"end:bar"
      This is the first chunk to be printed,
      and is separate than the Bar group.
      Foo!
    end:foo
      This is logically separate from the foo group.
      There's nothing special about the identifiers,
      they just are more appropriately named.
    end:bar