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