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