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