Skip to content

Commit 9139741

Browse files
authored
Merge pull request #463 from etiennebarrie/endless-operators
Support endless operator methods
2 parents dcf0d9f + 7c31ea2 commit 9139741

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

indent/ruby.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ let s:ruby_indent_keywords =
9191
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
9292

9393
" Def without an end clause: def method_call(...) = <expression>
94-
let s:ruby_endless_def = '\<def\s\+\%(\k\+\.\)\=\k\+[!?]\=\%((.*)\|\s\)\s*='
94+
let s:ruby_endless_def =
95+
\ '\<def\s\+\%(\k\+\.\)\=\%(\k\+[=!?]\=\|' .
96+
\ '[-+*/%&^<>~!]\|' .
97+
\ '\*\*\|>>\|<<\|' .
98+
\ '===\?\|\!=\|=\~\|\!\~\|' .
99+
\ '<=>\|<=\|>=\|' .
100+
\ '[-+!\~]@\|\[\]' .
101+
\ '\)\%((.*)\|\s\)\s*='
95102

96103
" Regex used for words that, at the start of a line, remove a level of indent.
97104
let s:ruby_deindent_keywords =

spec/indent/method_definitions_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,49 @@ def foo(
7474
# Reference: https://github.com/vim-ruby/vim-ruby/issues/450
7575
def self.foo = puts(bar)
7676
def bar.foo = puts(baz)
77+
78+
def +(other) = to_r + other
79+
def -(other) = to_r - other
80+
def *(other) = to_r * other
81+
def **(other) = to_r ** other
82+
def /(other) = to_r / other
83+
def %(other) = to_i % other
84+
def &(other) = to_i & other
85+
def ^(other) = to_i ^ other
86+
def >>(other) = to_i >> other
87+
def <<(other) = to_i << other
88+
def ==(other) = to_r == other
89+
def !=(other) = to_r != other
90+
91+
def ===(other) = to_r === other
92+
def foo.===(other) = other
93+
94+
def =~(other) = to_s =~ other
95+
def foo.=~(other) = other
96+
97+
def !~(other) = to_s !~ other
98+
def foo.!~(other) = other
99+
100+
def <=>(other) = to_r <=> other
101+
def foo.<=>(other) = other
102+
103+
def <(other) = to_r < other
104+
def >(other) = to_r > other
105+
106+
def <=(other) = to_r <= other
107+
def foo.<=(other) = other
108+
def >=(other) = to_r >= other
109+
def foo.>=(other) = other
110+
111+
def ! = false
112+
def ~ = ~to_i
113+
114+
def -@ = -to_r
115+
def +@ = to_r
116+
def !@ = false
117+
def ~@ = ~to_i
118+
119+
def [](i) = @array[i]
77120
end
78121
EOF
79122
end

0 commit comments

Comments
 (0)