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