2013-10-05 14:37:08 -04:00
|
|
|
if something_wrong? # ruby-move-to-block-skips-heredoc
|
|
|
|
ActiveSupport::Deprecation.warn(<<-eowarn)
|
|
|
|
boo hoo
|
|
|
|
end
|
|
|
|
eowarn
|
2013-11-04 12:50:47 +02:00
|
|
|
foo
|
2016-01-21 00:26:05 +03:00
|
|
|
|
|
|
|
foo(<<~squiggly)
|
|
|
|
end
|
|
|
|
squiggly
|
2013-10-05 14:37:08 -04:00
|
|
|
end
|
|
|
|
|
2014-05-27 10:28:07 -04:00
|
|
|
def foo
|
|
|
|
%^bar^
|
|
|
|
end
|
|
|
|
|
2012-08-14 08:38:11 -04:00
|
|
|
# Percent literals.
|
2012-04-24 13:06:12 -04:00
|
|
|
b = %Q{This is a "string"}
|
2012-08-14 08:38:11 -04:00
|
|
|
c = %w!foo
|
2012-04-24 13:06:12 -04:00
|
|
|
bar
|
2012-08-14 08:38:11 -04:00
|
|
|
baz!
|
|
|
|
d = %(hello (nested) world)
|
|
|
|
|
|
|
|
# Don't propertize percent literals inside strings.
|
|
|
|
"(%s, %s)" % [123, 456]
|
|
|
|
|
2016-03-12 00:18:42 +02:00
|
|
|
"abc/#{ddf}ghi"
|
|
|
|
"abc\#{ddf}ghi"
|
2014-05-10 16:07:01 -04:00
|
|
|
|
2012-08-14 08:38:11 -04:00
|
|
|
# Or inside comments.
|
|
|
|
x = # "tot %q/to"; =
|
2013-05-08 16:25:57 -04:00
|
|
|
y = 2 / 3
|
2012-08-14 08:38:11 -04:00
|
|
|
|
|
|
|
# Regexp after whitelisted method.
|
|
|
|
"abc".sub /b/, 'd'
|
|
|
|
|
2020-09-21 15:41:43 +02:00
|
|
|
# Don't mismatch "sub" at the end of words.
|
2012-08-14 08:38:11 -04:00
|
|
|
a = asub / aslb + bsub / bslb;
|
2012-04-24 13:06:12 -04:00
|
|
|
|
2012-08-14 08:38:11 -04:00
|
|
|
# Highlight the regexp after "if".
|
|
|
|
x = toto / foo if /do bar/ =~ "dobar"
|
2012-04-24 13:06:12 -04:00
|
|
|
|
2014-03-02 00:04:59 +02:00
|
|
|
# Regexp options are highlighted.
|
|
|
|
|
|
|
|
/foo/xi != %r{bar}mo.tee
|
|
|
|
|
2015-03-08 20:57:47 +02:00
|
|
|
foo { /"tee/
|
|
|
|
bar { |qux| /'fee"/ } # bug#20026
|
|
|
|
}
|
|
|
|
|
2013-10-05 14:37:08 -04:00
|
|
|
bar(class: XXX) do # ruby-indent-keyword-label
|
|
|
|
foo
|
|
|
|
end
|
|
|
|
bar
|
|
|
|
|
|
|
|
foo = [1, # ruby-deep-indent
|
|
|
|
2]
|
|
|
|
|
|
|
|
foo = { # ruby-deep-indent-disabled
|
2013-10-06 03:46:28 +03:00
|
|
|
a: b
|
2013-10-05 14:37:08 -04:00
|
|
|
}
|
|
|
|
|
2013-10-24 04:47:28 +04:00
|
|
|
foo = { a: b,
|
2013-10-23 13:55:53 -04:00
|
|
|
a1: b1
|
|
|
|
}
|
|
|
|
|
2013-12-14 08:46:13 +02:00
|
|
|
foo({ # bug#16118
|
|
|
|
a: b,
|
|
|
|
c: d
|
2013-12-17 03:31:55 +02:00
|
|
|
})
|
2013-12-14 08:46:13 +02:00
|
|
|
|
|
|
|
bar = foo(
|
2013-12-19 06:21:44 +02:00
|
|
|
a, [
|
|
|
|
1,
|
|
|
|
],
|
|
|
|
:qux => [
|
|
|
|
3
|
|
|
|
])
|
2013-12-14 08:46:13 +02:00
|
|
|
|
|
|
|
foo(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
a: b
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
c: d
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
foo([{
|
|
|
|
a: 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
b: 3
|
|
|
|
},
|
|
|
|
4
|
2013-12-17 03:31:55 +02:00
|
|
|
])
|
2013-10-21 07:50:06 +04:00
|
|
|
|
2013-10-05 14:37:08 -04:00
|
|
|
foo = [ # ruby-deep-indent-disabled
|
|
|
|
1
|
|
|
|
]
|
|
|
|
|
|
|
|
foo( # ruby-deep-indent-disabled
|
|
|
|
a
|
|
|
|
)
|
|
|
|
|
2013-05-19 10:01:23 +04:00
|
|
|
# Multiline regexp.
|
|
|
|
/bars
|
|
|
|
tees # toots
|
2021-02-02 03:47:46 +02:00
|
|
|
nfoos::/
|
2013-05-19 10:01:23 +04:00
|
|
|
|
2013-05-08 16:25:57 -04:00
|
|
|
def test1(arg)
|
|
|
|
puts "hello"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test2 (arg)
|
|
|
|
a = "apple"
|
|
|
|
|
|
|
|
if a == 2
|
|
|
|
puts "hello"
|
|
|
|
else
|
|
|
|
puts "there"
|
|
|
|
end
|
|
|
|
|
|
|
|
if a == 2 then
|
|
|
|
puts "hello"
|
|
|
|
elsif a == 3
|
|
|
|
puts "hello3"
|
|
|
|
elsif a == 3 then
|
|
|
|
puts "hello3"
|
|
|
|
else
|
|
|
|
puts "there"
|
|
|
|
end
|
|
|
|
|
2013-12-20 07:20:33 +02:00
|
|
|
b = case a
|
|
|
|
when "a"
|
|
|
|
6
|
|
|
|
# Support for this syntax was removed in Ruby 1.9, so we
|
|
|
|
# probably don't need to handle it either.
|
|
|
|
# when "b" :
|
|
|
|
# 7
|
|
|
|
# when "c" : 2
|
|
|
|
when "d" then 4
|
|
|
|
else 5
|
|
|
|
end
|
2013-05-08 16:25:57 -04:00
|
|
|
end
|
|
|
|
|
2012-04-24 13:06:12 -04:00
|
|
|
# Some Cucumber code:
|
|
|
|
Given /toto/ do
|
|
|
|
print "hello"
|
|
|
|
end
|
2013-09-03 03:29:10 +03:00
|
|
|
|
|
|
|
# Bug#15208
|
|
|
|
if something == :==
|
|
|
|
do_something
|
2014-02-01 16:54:58 +02:00
|
|
|
|
|
|
|
return false unless method == :+
|
|
|
|
x = y + z # Bug#16609
|
|
|
|
|
|
|
|
a = 1 ? 2 :(
|
|
|
|
2 + 3
|
|
|
|
)
|
2013-09-03 03:29:10 +03:00
|
|
|
end
|
2013-09-16 02:42:26 +03:00
|
|
|
|
2014-03-27 08:53:13 +02:00
|
|
|
# Bug#17097
|
|
|
|
if x == :!=
|
|
|
|
something
|
|
|
|
end
|
|
|
|
|
2016-03-09 16:43:51 +02:00
|
|
|
qux :+,
|
|
|
|
bar,
|
|
|
|
:[]=,
|
|
|
|
bar,
|
|
|
|
:a
|
|
|
|
|
2022-12-17 03:30:52 +02:00
|
|
|
zzz @abc,
|
|
|
|
4
|
|
|
|
|
2022-12-18 14:01:47 +02:00
|
|
|
foo a = 5,
|
|
|
|
b
|
|
|
|
|
2016-03-10 04:13:25 +02:00
|
|
|
b = $:
|
|
|
|
c = ??
|
|
|
|
|
2022-10-15 11:17:51 +02:00
|
|
|
# Example from https://ruby-doc.com/docs/ProgrammingRuby/
|
2013-10-06 23:38:26 -04:00
|
|
|
d = 4 + 5 + # no '\' needed
|
|
|
|
6 + 7
|
|
|
|
|
2022-10-15 11:17:51 +02:00
|
|
|
# Example from https://www.ruby-doc.org/docs/ProgrammingRuby/
|
2013-10-06 23:38:26 -04:00
|
|
|
e = 8 + 9 \
|
|
|
|
+ 10 # '\' needed
|
|
|
|
|
2013-11-08 04:31:51 +02:00
|
|
|
foo = obj.bar { |m| tee(m) } +
|
|
|
|
obj.qux { |m| hum(m) }
|
|
|
|
|
2013-10-06 03:46:28 +03:00
|
|
|
begin
|
|
|
|
foo
|
|
|
|
ensure
|
|
|
|
bar
|
|
|
|
end
|
|
|
|
|
2013-09-16 02:42:26 +03:00
|
|
|
# Bug#15369
|
2013-10-07 16:27:29 +03:00
|
|
|
MSG = 'Separate every 3 digits in the integer portion of a number' \
|
2013-10-05 14:37:08 -04:00
|
|
|
'with underscores(_).'
|
2013-10-06 03:46:28 +03:00
|
|
|
|
2013-10-06 23:38:26 -04:00
|
|
|
class C
|
|
|
|
def foo
|
|
|
|
self.end
|
|
|
|
D.new.class
|
|
|
|
end
|
2016-03-10 14:35:45 +02:00
|
|
|
|
|
|
|
def begin
|
|
|
|
end
|
2013-10-06 23:38:26 -04:00
|
|
|
end
|
2013-10-06 03:46:28 +03:00
|
|
|
|
|
|
|
a = foo(j, k) -
|
2013-10-06 23:38:26 -04:00
|
|
|
bar_tee
|
2013-10-06 03:46:28 +03:00
|
|
|
|
|
|
|
while a < b do # "do" is optional
|
|
|
|
foo
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "foo foo" \
|
2013-10-06 23:38:26 -04:00
|
|
|
"bar bar"
|
2013-10-06 04:21:51 +03:00
|
|
|
|
|
|
|
foo.
|
|
|
|
bar
|
|
|
|
|
2013-10-07 16:27:29 +03:00
|
|
|
# https://github.com/rails/rails/blob/17f5d8e062909f1fcae25351834d8e89967b645e/activesupport/lib/active_support/time_with_zone.rb#L206
|
2016-03-15 03:15:18 +02:00
|
|
|
foo # comment intended to confuse the tokenizer
|
2013-10-06 04:21:51 +03:00
|
|
|
.bar
|
2013-10-07 16:27:29 +03:00
|
|
|
|
|
|
|
z = {
|
|
|
|
foo: {
|
|
|
|
a: "aaa",
|
|
|
|
b: "bbb"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 06:18:01 +03:00
|
|
|
foo if
|
|
|
|
bar
|
|
|
|
|
2016-03-06 23:18:06 +02:00
|
|
|
fail "stuff" \
|
|
|
|
unless all_fine?
|
|
|
|
|
2013-10-11 05:11:37 +03:00
|
|
|
if foo?
|
|
|
|
bar
|
|
|
|
end
|
|
|
|
|
2013-10-14 04:51:20 +03:00
|
|
|
method arg1, # bug#15594
|
|
|
|
method2 arg2,
|
|
|
|
arg3
|
|
|
|
|
|
|
|
method? arg1,
|
|
|
|
arg2
|
|
|
|
|
|
|
|
method! arg1,
|
|
|
|
arg2
|
|
|
|
|
2013-10-26 05:16:37 +04:00
|
|
|
method !arg1,
|
|
|
|
arg2
|
|
|
|
|
|
|
|
method [],
|
|
|
|
arg2
|
|
|
|
|
|
|
|
method :foo,
|
|
|
|
:bar
|
|
|
|
|
|
|
|
method (a + b),
|
|
|
|
c, :d => :e,
|
|
|
|
f: g
|
|
|
|
|
2013-12-19 06:21:44 +02:00
|
|
|
desc "abc",
|
|
|
|
defg
|
|
|
|
|
2013-10-21 07:50:06 +04:00
|
|
|
it "is a method call with block" do |asd|
|
|
|
|
foo
|
|
|
|
end
|
|
|
|
|
|
|
|
it("is too!") {
|
|
|
|
bar
|
2013-12-22 08:04:40 +02:00
|
|
|
.qux
|
2013-10-21 07:50:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
and_this_one(has) { |block, parameters|
|
|
|
|
tee
|
|
|
|
}
|
|
|
|
|
2013-10-21 10:15:47 +04:00
|
|
|
if foo &&
|
2013-10-21 09:54:18 +04:00
|
|
|
bar
|
|
|
|
end
|
|
|
|
|
2013-10-07 16:27:29 +03:00
|
|
|
foo +
|
|
|
|
bar
|
|
|
|
|
2013-11-07 05:02:01 +02:00
|
|
|
foo and
|
|
|
|
bar
|
|
|
|
|
2013-11-08 04:31:51 +02:00
|
|
|
foo > bar &&
|
|
|
|
tee < qux
|
|
|
|
|
|
|
|
zux do
|
2016-03-16 04:32:59 +02:00
|
|
|
foo == bar &&
|
2013-11-08 04:31:51 +02:00
|
|
|
tee == qux
|
2016-03-16 04:32:59 +02:00
|
|
|
|
|
|
|
a = 3 and
|
|
|
|
b = 4
|
2013-11-08 04:31:51 +02:00
|
|
|
end
|
|
|
|
|
2016-03-16 04:32:59 +02:00
|
|
|
foo + bar ==
|
|
|
|
tee + qux
|
|
|
|
|
|
|
|
1 .. 2 &&
|
|
|
|
3
|
|
|
|
|
|
|
|
3 < 4 +
|
|
|
|
5
|
|
|
|
|
|
|
|
10 << 4 ^
|
|
|
|
20
|
|
|
|
|
|
|
|
100 + 2 >>
|
|
|
|
3
|
|
|
|
|
|
|
|
2 ** 10 /
|
|
|
|
2
|
|
|
|
|
2013-11-07 05:02:01 +02:00
|
|
|
foo ^
|
|
|
|
bar
|
|
|
|
|
2013-10-22 02:25:59 +04:00
|
|
|
foo_bar_tee(1, 2, 3)
|
2016-03-12 00:18:42 +02:00
|
|
|
.qux&.bar
|
|
|
|
.tee.bar
|
|
|
|
&.tee
|
2013-10-22 02:25:59 +04:00
|
|
|
|
2013-10-23 00:47:29 +04:00
|
|
|
foo do
|
|
|
|
bar
|
|
|
|
.tee
|
|
|
|
end
|
|
|
|
|
|
|
|
def bar
|
|
|
|
foo
|
|
|
|
.baz
|
|
|
|
end
|
|
|
|
|
2016-03-14 00:15:06 +02:00
|
|
|
abc(foo
|
|
|
|
.bar,
|
|
|
|
tee
|
|
|
|
.qux)
|
|
|
|
|
2020-10-24 20:22:33 +02:00
|
|
|
# https://stackoverflow.com/questions/17786563/emacs-ruby-mode-if-expressions-indentation
|
2013-10-27 07:25:03 +04:00
|
|
|
tee = if foo
|
|
|
|
bar
|
2013-12-19 07:06:24 +02:00
|
|
|
else
|
|
|
|
tee
|
2013-10-27 07:25:03 +04:00
|
|
|
end
|
|
|
|
|
2013-11-02 09:18:11 +04:00
|
|
|
a = b {
|
|
|
|
c
|
|
|
|
}
|
|
|
|
|
|
|
|
aa = bb do
|
|
|
|
cc
|
|
|
|
end
|
|
|
|
|
2013-11-04 13:04:50 +02:00
|
|
|
foo :bar do
|
|
|
|
qux
|
|
|
|
end
|
|
|
|
|
2013-11-08 04:31:51 +02:00
|
|
|
foo do |*args|
|
|
|
|
tee
|
|
|
|
end
|
|
|
|
|
|
|
|
bar do |&block|
|
|
|
|
tee
|
|
|
|
end
|
|
|
|
|
2013-10-09 06:18:01 +03:00
|
|
|
foo = [1, 2, 3].map do |i|
|
|
|
|
i + 1
|
|
|
|
end
|
2013-10-11 23:45:14 +03:00
|
|
|
|
2013-11-07 03:58:12 +02:00
|
|
|
bar.foo do
|
2013-10-22 02:25:59 +04:00
|
|
|
bar
|
|
|
|
end
|
2013-11-07 05:02:01 +02:00
|
|
|
|
2013-11-08 04:31:51 +02:00
|
|
|
bar.foo(tee) do
|
|
|
|
bar
|
|
|
|
end
|
2013-11-07 05:02:01 +02:00
|
|
|
|
2013-11-08 04:31:51 +02:00
|
|
|
bar.foo(tee) {
|
2013-11-07 05:02:01 +02:00
|
|
|
bar
|
2013-11-08 04:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bar 1 do
|
|
|
|
foo 2 do
|
|
|
|
tee
|
|
|
|
end
|
2013-11-07 05:02:01 +02:00
|
|
|
end
|
2013-11-08 05:30:24 +02:00
|
|
|
|
2013-11-12 16:15:14 +02:00
|
|
|
foo |
|
|
|
|
bar
|
|
|
|
|
2013-11-09 01:59:56 +02:00
|
|
|
def qux
|
|
|
|
foo ||= begin
|
2013-12-20 07:20:33 +02:00
|
|
|
bar
|
|
|
|
tee
|
|
|
|
rescue
|
|
|
|
oomph
|
|
|
|
end
|
2013-11-09 01:59:56 +02:00
|
|
|
end
|
2013-12-09 06:19:16 +02:00
|
|
|
|
2014-01-17 05:15:02 +02:00
|
|
|
private def foo
|
|
|
|
bar
|
|
|
|
end
|
|
|
|
|
2013-12-09 06:19:16 +02:00
|
|
|
%^abc^
|
|
|
|
ddd
|
2013-12-17 14:04:23 +02:00
|
|
|
|
2014-01-31 19:13:49 +02:00
|
|
|
qux = foo.fee ?
|
2013-12-17 14:04:23 +02:00
|
|
|
bar :
|
|
|
|
tee
|
2013-12-19 06:21:44 +02:00
|
|
|
|
|
|
|
zoo.keep.bar!(
|
|
|
|
{x: y,
|
|
|
|
z: t})
|
|
|
|
|
|
|
|
zoo
|
|
|
|
.lose(
|
2014-01-31 19:13:49 +02:00
|
|
|
q, p)
|
2013-12-22 04:31:21 +02:00
|
|
|
|
2014-02-23 10:26:40 +02:00
|
|
|
a.records().map(&:b).zip(
|
|
|
|
foo)
|
|
|
|
|
2016-03-15 03:12:19 +02:00
|
|
|
foo1 =
|
|
|
|
subject.update(
|
|
|
|
1
|
|
|
|
)
|
|
|
|
|
|
|
|
foo2 =
|
|
|
|
subject.
|
|
|
|
update(
|
|
|
|
2
|
|
|
|
)
|
|
|
|
|
2014-02-23 10:26:40 +02:00
|
|
|
# FIXME: This is not consistent with the example below it, but this
|
2014-02-25 10:40:54 -08:00
|
|
|
# offset only happens if the colon is at eol, which wouldn't be often.
|
2014-02-23 10:26:40 +02:00
|
|
|
# Tokenizing `bar:' as `:bar =>' would be better, but it's hard to
|
|
|
|
# distinguish from a variable reference inside a ternary operator.
|
2013-12-22 04:31:21 +02:00
|
|
|
foo(bar:
|
|
|
|
tee)
|
|
|
|
|
|
|
|
foo(:bar =>
|
2014-02-23 07:53:53 +02:00
|
|
|
tee)
|
|
|
|
|
2016-03-14 00:34:01 +02:00
|
|
|
regions = foo(
|
|
|
|
OpenStruct.new(id: 0, name: "foo") => [
|
|
|
|
10
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2014-02-23 07:53:53 +02:00
|
|
|
{'a' => {
|
|
|
|
'b' => 'c',
|
|
|
|
'd' => %w(e f)
|
|
|
|
}
|
|
|
|
}
|
2014-03-21 06:26:39 +02:00
|
|
|
|
|
|
|
# Bug#17050
|
|
|
|
|
|
|
|
return render json: {
|
|
|
|
errors: { base: [message] },
|
|
|
|
copying: copying
|
|
|
|
},
|
|
|
|
status: 400
|
|
|
|
|
|
|
|
top test(
|
|
|
|
some,
|
|
|
|
top,
|
|
|
|
test)
|
|
|
|
|
|
|
|
foo bar, {
|
|
|
|
tee: qux
|
|
|
|
}
|
2020-12-31 18:39:22 +02:00
|
|
|
|
|
|
|
# Bug#42846, bug#18644
|
|
|
|
|
|
|
|
:foo=
|
|
|
|
# indent here
|
|
|
|
2 = 3
|
|
|
|
:foo= if true
|
|
|
|
{:abc=>4} # not indented, and '=' is not highlighted
|
2022-03-21 03:18:36 +02:00
|
|
|
|
|
|
|
# Pattern matching
|
|
|
|
case translation
|
|
|
|
in ['th', orig_text, 'en', trans_text]
|
|
|
|
puts "English translation: #{orig_text} => #{trans_text}"
|
|
|
|
in {'th' => orig_text, 'ja' => trans_text}
|
|
|
|
puts "Japanese translation: #{orig_text} => #{trans_text}"
|
|
|
|
end
|
2022-04-26 05:36:35 +03:00
|
|
|
|
|
|
|
# Tokenizing "**" and "|" separately.
|
|
|
|
def resolve(**args)
|
|
|
|
members = proc do |**args|
|
|
|
|
p(**args)
|
|
|
|
end
|
|
|
|
|
|
|
|
member.call(**args)
|
|
|
|
end
|
2022-12-18 14:01:47 +02:00
|
|
|
|
|
|
|
# Endless methods.
|
|
|
|
class Bar
|
|
|
|
def foo(abc) = bar +
|
|
|
|
baz
|
|
|
|
|
|
|
|
def self.bar =
|
|
|
|
123 +
|
|
|
|
4
|
|
|
|
|
|
|
|
def foo(...) = z
|
|
|
|
|
|
|
|
def request_params = {
|
|
|
|
headers: request_headers,
|
|
|
|
body: request_body
|
|
|
|
}
|
|
|
|
|
|
|
|
def self.foo(
|
|
|
|
baz,
|
|
|
|
bar
|
|
|
|
) =
|
|
|
|
what
|
|
|
|
|
|
|
|
def foo=(
|
|
|
|
baz,
|
|
|
|
bar
|
|
|
|
)
|
2022-12-19 02:21:51 +02:00
|
|
|
def baz.full_name = "#{bar} 3"
|
|
|
|
|
|
|
|
baz
|
2022-12-18 14:01:47 +02:00
|
|
|
end
|
|
|
|
end
|