mirror of
https://github.com/jbranchaud/til
synced 2026-01-16 21:48:02 +00:00
Compare commits
4 Commits
7212fcbf27
...
36b90c5232
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36b90c5232 | ||
|
|
1c9e12b96f | ||
|
|
5615da920f | ||
|
|
c60c63f554 |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1532 TILs and counting..._
|
||||
_1533 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -191,7 +191,7 @@ _1532 TILs and counting..._
|
||||
- [Aliasing An Ansible Host](devops/aliasing-an-ansible-host.md)
|
||||
- [Allow Cross-Origin Requests To Include Cookies](devops/allow-cross-origin-requests-to-include-cookies.md)
|
||||
- [Allow HTTPS Through Your UFW Firewall](devops/allow-https-through-your-ufw-firewall.md)
|
||||
- [Check For Cached Site Assocation File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
||||
- [Check For Cached Site Association File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
||||
- [Check The Status of All Services](devops/check-the-status-of-all-services.md)
|
||||
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
|
||||
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
|
||||
@@ -737,7 +737,7 @@ _1532 TILs and counting..._
|
||||
- [Check If Clusters Are Upgrade Compatible](postgres/check-if-clusters-are-upgrade-compatible.md)
|
||||
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
||||
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
||||
- [Check Table For Any Oprhaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||
- [Check Table For Any Orphaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||
- [Checking Inequality](postgres/checking-inequality.md)
|
||||
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)
|
||||
- [Clear The Screen In psql](postgres/clear-the-screen-in-psql.md)
|
||||
@@ -1223,6 +1223,7 @@ _1532 TILs and counting..._
|
||||
- [Define Multiline Strings With Heredocs](ruby/define-multiline-strings-with-heredocs.md)
|
||||
- [Destructure The First Item From An Array](ruby/destructure-the-first-item-from-an-array.md)
|
||||
- [Destructuring Arrays In Blocks](ruby/destructuring-arrays-in-blocks.md)
|
||||
- [Disable Interpolation For A Heredoc String](ruby/disable-interpolation-for-a-heredoc-string.md)
|
||||
- [Disassemble Some Codes](ruby/disassemble-some-codes.md)
|
||||
- [Double Splat To Merge Hashes](ruby/double-splat-to-merge-hashes.md)
|
||||
- [Edit Previous Parts Of The Pry Buffer History](ruby/edit-previous-parts-of-the-pry-buffer-history.md)
|
||||
|
||||
41
ruby/disable-interpolation-for-a-heredoc-string.md
Normal file
41
ruby/disable-interpolation-for-a-heredoc-string.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Disable Interpolation For A Heredoc String
|
||||
|
||||
As a matter of convenience, a heredoc performs string interpolation by default.
|
||||
|
||||
Here is an example of that.
|
||||
|
||||
```ruby
|
||||
irb(main):087> word = 'taco'
|
||||
=> "taco"
|
||||
irb(main):088" puts <<-TEXT
|
||||
irb(main):089" I want to eat a #{word}!
|
||||
irb(main):090> TEXT
|
||||
I want to eat a taco!
|
||||
=> nil
|
||||
```
|
||||
|
||||
A much less common scenario is that we don't want string interpolation to take
|
||||
place. For whatever reason, we want the exact string to be preserved. To
|
||||
achieve that, we can wrap the opening heredoc identifier in single quotes.
|
||||
|
||||
As you can see, the `#{word}` portion is preserved.
|
||||
|
||||
```ruby
|
||||
irb(main):091> word = 'taco'
|
||||
=> "taco"
|
||||
irb(main):092' puts <<-'TEXT'
|
||||
irb(main):093' I want to eat a #{word}!
|
||||
irb(main):094> TEXT
|
||||
I want to eat a #{word}!
|
||||
=> nil
|
||||
```
|
||||
|
||||
This syntax puts the heredoc in single-quote mode. I left the IRB line preamble
|
||||
in for each codeblock so that you can see the difference. The first example
|
||||
(lines 88 and 89) shows the heredoc is double-quoted. The second example (lines
|
||||
92 and 93) shows the heredoc is single quoted.
|
||||
|
||||
Note: the closing heredoc identifier (`TEXT` in this case) is not wrapped in
|
||||
single quotes, just the opening one.
|
||||
|
||||
[source](https://ruby-doc.org/3.3.6/syntax/literals_rdoc.html#label-Here+Document+Literals)
|
||||
Reference in New Issue
Block a user