Commit | Line | Data |
---|---|---|
34d1a133 SM |
1 | if something_wrong? # ruby-move-to-block-skips-heredoc |
2 | ActiveSupport::Deprecation.warn(<<-eowarn) | |
3 | boo hoo | |
4 | end | |
5 | eowarn | |
dca01b09 | 6 | foo |
34d1a133 SM |
7 | end |
8 | ||
f063063a | 9 | # Percent literals. |
dfbd787f | 10 | b = %Q{This is a "string"} |
f063063a | 11 | c = %w!foo |
dfbd787f | 12 | bar |
f063063a DG |
13 | baz! |
14 | d = %(hello (nested) world) | |
15 | ||
16 | # Don't propertize percent literals inside strings. | |
17 | "(%s, %s)" % [123, 456] | |
18 | ||
19 | # Or inside comments. | |
20 | x = # "tot %q/to"; = | |
a9e4425b | 21 | y = 2 / 3 |
f063063a DG |
22 | |
23 | # Regexp after whitelisted method. | |
24 | "abc".sub /b/, 'd' | |
25 | ||
26 | # Don't mis-match "sub" at the end of words. | |
27 | a = asub / aslb + bsub / bslb; | |
dfbd787f | 28 | |
f063063a DG |
29 | # Highlight the regexp after "if". |
30 | x = toto / foo if /do bar/ =~ "dobar" | |
dfbd787f | 31 | |
34d1a133 SM |
32 | bar(class: XXX) do # ruby-indent-keyword-label |
33 | foo | |
34 | end | |
35 | bar | |
36 | ||
37 | foo = [1, # ruby-deep-indent | |
38 | 2] | |
39 | ||
40 | foo = { # ruby-deep-indent-disabled | |
5cd9cda9 | 41 | a: b |
34d1a133 SM |
42 | } |
43 | ||
369bbf71 | 44 | foo = { a: b, |
03d44565 SM |
45 | a1: b1 |
46 | } | |
47 | ||
276bc333 DG |
48 | foo({ # bug#16118 |
49 | a: b, | |
50 | c: d | |
5556c0ce | 51 | }) |
276bc333 DG |
52 | |
53 | bar = foo( | |
7e1549c9 DG |
54 | a, [ |
55 | 1, | |
56 | ], | |
57 | :qux => [ | |
58 | 3 | |
59 | ]) | |
276bc333 DG |
60 | |
61 | foo( | |
62 | [ | |
63 | { | |
64 | a: b | |
65 | }, | |
66 | ], | |
67 | { | |
68 | c: d | |
69 | } | |
70 | ) | |
71 | ||
72 | foo([{ | |
73 | a: 2 | |
74 | }, | |
75 | { | |
76 | b: 3 | |
77 | }, | |
78 | 4 | |
5556c0ce | 79 | ]) |
8c1ae481 | 80 | |
34d1a133 SM |
81 | foo = [ # ruby-deep-indent-disabled |
82 | 1 | |
83 | ] | |
84 | ||
85 | foo( # ruby-deep-indent-disabled | |
86 | a | |
87 | ) | |
88 | ||
1a0a0a8a DG |
89 | # Multiline regexp. |
90 | /bars | |
91 | tees # toots | |
92 | nfoos/ | |
93 | ||
a9e4425b SM |
94 | def test1(arg) |
95 | puts "hello" | |
96 | end | |
97 | ||
98 | def test2 (arg) | |
99 | a = "apple" | |
100 | ||
101 | if a == 2 | |
102 | puts "hello" | |
103 | else | |
104 | puts "there" | |
105 | end | |
106 | ||
107 | if a == 2 then | |
108 | puts "hello" | |
109 | elsif a == 3 | |
110 | puts "hello3" | |
111 | elsif a == 3 then | |
112 | puts "hello3" | |
113 | else | |
114 | puts "there" | |
115 | end | |
116 | ||
b520f210 DG |
117 | b = case a |
118 | when "a" | |
119 | 6 | |
120 | # Support for this syntax was removed in Ruby 1.9, so we | |
121 | # probably don't need to handle it either. | |
122 | # when "b" : | |
123 | # 7 | |
124 | # when "c" : 2 | |
125 | when "d" then 4 | |
126 | else 5 | |
127 | end | |
a9e4425b SM |
128 | end |
129 | ||
dfbd787f SM |
130 | # Some Cucumber code: |
131 | Given /toto/ do | |
132 | print "hello" | |
133 | end | |
88527bc0 DG |
134 | |
135 | # Bug#15208 | |
136 | if something == :== | |
137 | do_something | |
a09beb3d DG |
138 | |
139 | return false unless method == :+ | |
140 | x = y + z # Bug#16609 | |
141 | ||
142 | a = 1 ? 2 :( | |
143 | 2 + 3 | |
144 | ) | |
88527bc0 | 145 | end |
578c21bc | 146 | |
7ccae3b1 SM |
147 | # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html |
148 | d = 4 + 5 + # no '\' needed | |
149 | 6 + 7 | |
150 | ||
151 | # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html | |
152 | e = 8 + 9 \ | |
153 | + 10 # '\' needed | |
154 | ||
1f923923 DG |
155 | foo = obj.bar { |m| tee(m) } + |
156 | obj.qux { |m| hum(m) } | |
157 | ||
5cd9cda9 DG |
158 | begin |
159 | foo | |
160 | ensure | |
161 | bar | |
162 | end | |
163 | ||
578c21bc | 164 | # Bug#15369 |
2f84ba10 | 165 | MSG = 'Separate every 3 digits in the integer portion of a number' \ |
34d1a133 | 166 | 'with underscores(_).' |
5cd9cda9 | 167 | |
7ccae3b1 SM |
168 | class C |
169 | def foo | |
170 | self.end | |
171 | D.new.class | |
172 | end | |
173 | end | |
5cd9cda9 DG |
174 | |
175 | a = foo(j, k) - | |
7ccae3b1 | 176 | bar_tee |
5cd9cda9 DG |
177 | |
178 | while a < b do # "do" is optional | |
179 | foo | |
180 | end | |
181 | ||
182 | desc "foo foo" \ | |
7ccae3b1 | 183 | "bar bar" |
7318480c DG |
184 | |
185 | foo. | |
186 | bar | |
187 | ||
2f84ba10 | 188 | # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206 |
7318480c DG |
189 | foo |
190 | .bar | |
2f84ba10 DG |
191 | |
192 | z = { | |
193 | foo: { | |
194 | a: "aaa", | |
195 | b: "bbb" | |
196 | } | |
197 | } | |
198 | ||
238150c8 DG |
199 | foo if |
200 | bar | |
201 | ||
b68e2926 DG |
202 | if foo? |
203 | bar | |
204 | end | |
205 | ||
1eda1d8d DG |
206 | method arg1, # bug#15594 |
207 | method2 arg2, | |
208 | arg3 | |
209 | ||
210 | method? arg1, | |
211 | arg2 | |
212 | ||
213 | method! arg1, | |
214 | arg2 | |
215 | ||
bae91342 DG |
216 | method !arg1, |
217 | arg2 | |
218 | ||
219 | method [], | |
220 | arg2 | |
221 | ||
222 | method :foo, | |
223 | :bar | |
224 | ||
225 | method (a + b), | |
226 | c, :d => :e, | |
227 | f: g | |
228 | ||
7e1549c9 DG |
229 | desc "abc", |
230 | defg | |
231 | ||
8c1ae481 DG |
232 | it "is a method call with block" do |asd| |
233 | foo | |
234 | end | |
235 | ||
236 | it("is too!") { | |
237 | bar | |
f2351498 | 238 | .qux |
8c1ae481 DG |
239 | } |
240 | ||
241 | and_this_one(has) { |block, parameters| | |
242 | tee | |
243 | } | |
244 | ||
c7e36328 | 245 | if foo && |
cfef16c0 DG |
246 | bar |
247 | end | |
248 | ||
2f84ba10 DG |
249 | foo + |
250 | bar | |
251 | ||
1d1c86da DG |
252 | foo and |
253 | bar | |
254 | ||
1f923923 DG |
255 | foo > bar && |
256 | tee < qux | |
257 | ||
258 | zux do | |
259 | foo == bar and | |
260 | tee == qux | |
261 | end | |
262 | ||
1d1c86da DG |
263 | foo ^ |
264 | bar | |
265 | ||
18cacc39 | 266 | foo_bar_tee(1, 2, 3) |
e2a67bd0 DG |
267 | .qux.bar |
268 | .tee | |
18cacc39 | 269 | |
a6462ef5 DG |
270 | foo do |
271 | bar | |
272 | .tee | |
273 | end | |
274 | ||
275 | def bar | |
276 | foo | |
277 | .baz | |
278 | end | |
279 | ||
c8c605ac DG |
280 | # http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation |
281 | tee = if foo | |
282 | bar | |
ce41edb4 DG |
283 | else |
284 | tee | |
c8c605ac DG |
285 | end |
286 | ||
3d42b968 DG |
287 | a = b { |
288 | c | |
289 | } | |
290 | ||
291 | aa = bb do | |
292 | cc | |
293 | end | |
294 | ||
41784d0b DG |
295 | foo :bar do |
296 | qux | |
297 | end | |
298 | ||
1f923923 DG |
299 | foo do |*args| |
300 | tee | |
301 | end | |
302 | ||
303 | bar do |&block| | |
304 | tee | |
305 | end | |
306 | ||
238150c8 DG |
307 | foo = [1, 2, 3].map do |i| |
308 | i + 1 | |
309 | end | |
55ee77a3 | 310 | |
b420ccfc | 311 | bar.foo do |
18cacc39 | 312 | bar |
18cacc39 | 313 | end |
1d1c86da | 314 | |
1f923923 DG |
315 | bar.foo(tee) do |
316 | bar | |
317 | end | |
1d1c86da | 318 | |
1f923923 | 319 | bar.foo(tee) { |
1d1c86da | 320 | bar |
1f923923 DG |
321 | } |
322 | ||
323 | bar 1 do | |
324 | foo 2 do | |
325 | tee | |
326 | end | |
1d1c86da | 327 | end |
d85783ca | 328 | |
7b08f97e DG |
329 | foo | |
330 | bar | |
331 | ||
1629a329 DG |
332 | def qux |
333 | foo ||= begin | |
b520f210 DG |
334 | bar |
335 | tee | |
336 | rescue | |
337 | oomph | |
338 | end | |
1629a329 | 339 | end |
8212d9c0 | 340 | |
fb3d479c DG |
341 | private def foo |
342 | bar | |
343 | end | |
344 | ||
8212d9c0 DG |
345 | %^abc^ |
346 | ddd | |
35b249a6 | 347 | |
e2a67bd0 | 348 | qux = foo.fee ? |
35b249a6 DG |
349 | bar : |
350 | tee | |
7e1549c9 DG |
351 | |
352 | zoo.keep.bar!( | |
353 | {x: y, | |
354 | z: t}) | |
355 | ||
356 | zoo | |
357 | .lose( | |
e2a67bd0 | 358 | q, p) |
65a1da00 | 359 | |
dfdb365c DG |
360 | a.records().map(&:b).zip( |
361 | foo) | |
362 | ||
363 | # FIXME: This is not consistent with the example below it, but this | |
9a89cfa2 | 364 | # offset only happens if the colon is at eol, which wouldn't be often. |
dfdb365c DG |
365 | # Tokenizing `bar:' as `:bar =>' would be better, but it's hard to |
366 | # distinguish from a variable reference inside a ternary operator. | |
65a1da00 DG |
367 | foo(bar: |
368 | tee) | |
369 | ||
370 | foo(:bar => | |
62f95022 DG |
371 | tee) |
372 | ||
373 | {'a' => { | |
374 | 'b' => 'c', | |
375 | 'd' => %w(e f) | |
376 | } | |
377 | } |