Skip to content

Commit

Permalink
Merge pull request #211 from gsamokovarov/join-ruby-methods-without-a…
Browse files Browse the repository at this point in the history
…rguments

Fix joining single line Ruby methods without arguments
  • Loading branch information
AndrewRadev committed Aug 19, 2024
2 parents 3bfd24e + a8370b1 commit f72d59c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autoload/sj/ruby.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ endfunction

function! sj#ruby#JoinOnelineDef()
" adapted from vim-ruby
if search('\<def\s\+\%(\k\+\.\)\=\k\+[!?]\=\%((.*)\)\s*\%(#.*\)\=$', 'Wbc', line('.')) <= 0
if search('\<def\s\+\%(\k\+\.\)\=\k\+[!?]\=\s*\%((.*)\)\=\s*\%(#.*\)\=$', 'Wbc', line('.')) <= 0
return 0
endif

Expand Down
42 changes: 42 additions & 0 deletions spec/plugin/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1901,5 +1901,47 @@ def foo(one, two)
def foo(one, two) = bar
EOF
end

specify "with the cursor on a definition without arguments" do
set_file_contents <<~EOF
def foo = bar
EOF

vim.search 'def'
split

assert_file_contents <<~EOF
def foo
bar
end
EOF

join

assert_file_contents <<~EOF
def foo = bar
EOF
end

specify "with the cursor on a definition arguments defaults" do
set_file_contents <<~EOF
def self.foo(bar = quux(42), ...) = bar
EOF

vim.search 'def'
split

assert_file_contents <<~EOF
def self.foo(bar = quux(42), ...)
bar
end
EOF

join

assert_file_contents <<~EOF
def self.foo(bar = quux(42), ...) = bar
EOF
end
end
end

0 comments on commit f72d59c

Please sign in to comment.