Skip to content

Commit bd49b31

Browse files
committed
Add Multi-Line Comments as a Ruby TIL
1 parent 4ff1a38 commit bd49b31

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1436 TILs and counting..._
13+
_1437 TILs and counting..._
1414

1515
---
1616

@@ -1180,6 +1180,7 @@ _1436 TILs and counting..._
11801180
- [Map With Index Over An Array](ruby/map-with-index-over-an-array.md)
11811181
- [Mock Method Chain Calls With RSpec](ruby/mock-method-chain-calls-with-rspec.md)
11821182
- [Mocking Requests With Partial URIs Using Regex](ruby/mocking-requests-with-partial-uris-using-regex.md)
1183+
- [Multi-Line Comments](ruby/multi-line-comments.md)
11831184
- [Named Regex Captures Are Assigned To Variables](ruby/named-regex-captures-are-assigned-to-variables.md)
11841185
- [Navigate Back In The Browser With Capybara](ruby/navigate-back-in-the-browser-with-capybara.md)
11851186
- [Next And Previous Floats](ruby/next-and-previous-floats.md)

ruby/multi-line-comments.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Multi-Line Comments
2+
3+
Ruby has an obscure syntax for creating multi-line comments.
4+
5+
In many languages, there is a multi-line comment syntax that looks something
6+
like this:
7+
8+
```javascript
9+
/*
10+
* multi-line comment in javascript
11+
*/
12+
```
13+
14+
This gets used often in those languages.
15+
16+
In Ruby, the multi-line comment syntax is not something we see very often. It
17+
is a departure from the single-line comment syntax and it also requires no
18+
indentation.
19+
20+
```ruby
21+
RSpec.configure do |config|
22+
config.order = :random
23+
24+
# The settings below are suggested to provide a good initial experience
25+
# with RSpec, but feel free to customize to your heart's content.
26+
=begin
27+
# These two settings work together to allow you to limit a spec run
28+
# to individual examples or groups you care about by tagging them with
29+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
30+
# get run.
31+
config.filter_run :focus
32+
config.run_all_when_everything_filtered = true
33+
34+
# ...
35+
36+
=end
37+
end
38+
```
39+
40+
Using the `=begin` and `=end` syntax (no indentation), we make everything
41+
inbetween into a comment.
42+
43+
Though we don't see this too often, I did pull this example directly from the
44+
`spec_helper.rb` file that RSpec generates.
45+
46+
[source](https://docs.ruby-lang.org/en/master/syntax/comments_rdoc.html)

0 commit comments

Comments
 (0)