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 | |
51 | } | |
52 | ) # bug#16116 | |
53 | ||
54 | bar = foo( | |
55 | a, [ | |
56 | 1, | |
57 | ], | |
58 | :qux => [ | |
59 | 3 | |
60 | ] | |
61 | ) | |
62 | ||
63 | foo( | |
64 | [ | |
65 | { | |
66 | a: b | |
67 | }, | |
68 | ], | |
69 | { | |
70 | c: d | |
71 | } | |
72 | ) | |
73 | ||
74 | foo([{ | |
75 | a: 2 | |
76 | }, | |
77 | { | |
78 | b: 3 | |
79 | }, | |
80 | 4 | |
81 | ] | |
82 | ) | |
8c1ae481 | 83 | |
34d1a133 SM |
84 | foo = [ # ruby-deep-indent-disabled |
85 | 1 | |
86 | ] | |
87 | ||
88 | foo( # ruby-deep-indent-disabled | |
89 | a | |
90 | ) | |
91 | ||
1a0a0a8a DG |
92 | # Multiline regexp. |
93 | /bars | |
94 | tees # toots | |
95 | nfoos/ | |
96 | ||
a9e4425b SM |
97 | def test1(arg) |
98 | puts "hello" | |
99 | end | |
100 | ||
101 | def test2 (arg) | |
102 | a = "apple" | |
103 | ||
104 | if a == 2 | |
105 | puts "hello" | |
106 | else | |
107 | puts "there" | |
108 | end | |
109 | ||
110 | if a == 2 then | |
111 | puts "hello" | |
112 | elsif a == 3 | |
113 | puts "hello3" | |
114 | elsif a == 3 then | |
115 | puts "hello3" | |
116 | else | |
117 | puts "there" | |
118 | end | |
119 | ||
120 | case a | |
121 | when "a" | |
122 | 6 | |
1a0a0a8a DG |
123 | # Support for this syntax was removed in Ruby 1.9, so we |
124 | # probably don't need to handle it either. | |
a9e4425b SM |
125 | # when "b" : |
126 | # 7 | |
127 | # when "c" : 2 | |
128 | when "d" then 4 | |
129 | else 5 | |
130 | end | |
131 | end | |
132 | ||
dfbd787f SM |
133 | # Some Cucumber code: |
134 | Given /toto/ do | |
135 | print "hello" | |
136 | end | |
88527bc0 DG |
137 | |
138 | # Bug#15208 | |
139 | if something == :== | |
140 | do_something | |
141 | end | |
578c21bc | 142 | |
7ccae3b1 SM |
143 | # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html |
144 | d = 4 + 5 + # no '\' needed | |
145 | 6 + 7 | |
146 | ||
147 | # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html | |
148 | e = 8 + 9 \ | |
149 | + 10 # '\' needed | |
150 | ||
1f923923 DG |
151 | foo = obj.bar { |m| tee(m) } + |
152 | obj.qux { |m| hum(m) } | |
153 | ||
5cd9cda9 DG |
154 | begin |
155 | foo | |
156 | ensure | |
157 | bar | |
158 | end | |
159 | ||
578c21bc | 160 | # Bug#15369 |
2f84ba10 | 161 | MSG = 'Separate every 3 digits in the integer portion of a number' \ |
34d1a133 | 162 | 'with underscores(_).' |
5cd9cda9 | 163 | |
7ccae3b1 SM |
164 | class C |
165 | def foo | |
166 | self.end | |
167 | D.new.class | |
168 | end | |
169 | end | |
5cd9cda9 DG |
170 | |
171 | a = foo(j, k) - | |
7ccae3b1 | 172 | bar_tee |
5cd9cda9 DG |
173 | |
174 | while a < b do # "do" is optional | |
175 | foo | |
176 | end | |
177 | ||
178 | desc "foo foo" \ | |
7ccae3b1 | 179 | "bar bar" |
7318480c DG |
180 | |
181 | foo. | |
182 | bar | |
183 | ||
2f84ba10 | 184 | # https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206 |
7318480c DG |
185 | foo |
186 | .bar | |
2f84ba10 DG |
187 | |
188 | z = { | |
189 | foo: { | |
190 | a: "aaa", | |
191 | b: "bbb" | |
192 | } | |
193 | } | |
194 | ||
238150c8 DG |
195 | foo if |
196 | bar | |
197 | ||
b68e2926 DG |
198 | if foo? |
199 | bar | |
200 | end | |
201 | ||
1eda1d8d DG |
202 | method arg1, # bug#15594 |
203 | method2 arg2, | |
204 | arg3 | |
205 | ||
206 | method? arg1, | |
207 | arg2 | |
208 | ||
209 | method! arg1, | |
210 | arg2 | |
211 | ||
bae91342 DG |
212 | method !arg1, |
213 | arg2 | |
214 | ||
215 | method [], | |
216 | arg2 | |
217 | ||
218 | method :foo, | |
219 | :bar | |
220 | ||
221 | method (a + b), | |
222 | c, :d => :e, | |
223 | f: g | |
224 | ||
8c1ae481 DG |
225 | it "is a method call with block" do |asd| |
226 | foo | |
227 | end | |
228 | ||
229 | it("is too!") { | |
230 | bar | |
231 | } | |
232 | ||
233 | and_this_one(has) { |block, parameters| | |
234 | tee | |
235 | } | |
236 | ||
c7e36328 | 237 | if foo && |
cfef16c0 DG |
238 | bar |
239 | end | |
240 | ||
2f84ba10 DG |
241 | foo + |
242 | bar | |
243 | ||
1d1c86da DG |
244 | foo and |
245 | bar | |
246 | ||
1f923923 DG |
247 | foo > bar && |
248 | tee < qux | |
249 | ||
250 | zux do | |
251 | foo == bar and | |
252 | tee == qux | |
253 | end | |
254 | ||
1d1c86da DG |
255 | foo ^ |
256 | bar | |
257 | ||
18cacc39 DG |
258 | foo_bar_tee(1, 2, 3) |
259 | .qux | |
260 | .bar | |
261 | ||
a6462ef5 DG |
262 | foo do |
263 | bar | |
264 | .tee | |
265 | end | |
266 | ||
267 | def bar | |
268 | foo | |
269 | .baz | |
270 | end | |
271 | ||
c8c605ac DG |
272 | # http://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation |
273 | tee = if foo | |
274 | bar | |
275 | end | |
276 | ||
3d42b968 DG |
277 | a = b { |
278 | c | |
279 | } | |
280 | ||
281 | aa = bb do | |
282 | cc | |
283 | end | |
284 | ||
41784d0b DG |
285 | foo :bar do |
286 | qux | |
287 | end | |
288 | ||
1f923923 DG |
289 | foo do |*args| |
290 | tee | |
291 | end | |
292 | ||
293 | bar do |&block| | |
294 | tee | |
295 | end | |
296 | ||
238150c8 DG |
297 | foo = [1, 2, 3].map do |i| |
298 | i + 1 | |
299 | end | |
55ee77a3 | 300 | |
b420ccfc | 301 | bar.foo do |
18cacc39 | 302 | bar |
18cacc39 | 303 | end |
1d1c86da | 304 | |
1f923923 DG |
305 | bar.foo(tee) do |
306 | bar | |
307 | end | |
1d1c86da | 308 | |
1f923923 | 309 | bar.foo(tee) { |
1d1c86da | 310 | bar |
1f923923 DG |
311 | } |
312 | ||
313 | bar 1 do | |
314 | foo 2 do | |
315 | tee | |
316 | end | |
1d1c86da | 317 | end |
d85783ca | 318 | |
7b08f97e DG |
319 | foo | |
320 | bar | |
321 | ||
d85783ca DG |
322 | foo || |
323 | begin | |
324 | bar | |
325 | end | |
1629a329 DG |
326 | |
327 | def qux | |
328 | foo ||= begin | |
329 | bar | |
330 | tee | |
331 | end | |
332 | end | |
8212d9c0 DG |
333 | |
334 | %^abc^ | |
335 | ddd |