Skip to content

Commit

Permalink
Handle ivars (@ / @@) in ruby ternaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Griffin Smith committed Aug 3, 2015
1 parent c085b3c commit 1c0f6a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autoload/sj/ruby.vim
Expand Up @@ -59,7 +59,7 @@ endfunction

function! sj#ruby#SplitTernaryClause()
let line = getline('.')
let ternary_pattern = '\v(\w.*) \? (.*) : (.*)'
let ternary_pattern = '\v(\@{0,2}\w.*) \? (.*) : (.*)'
let assignment_pattern = '\v^\s*\w* \= '

if line =~ ternary_pattern
Expand Down
22 changes: 22 additions & 0 deletions spec/plugin/ruby_spec.rb
Expand Up @@ -188,6 +188,28 @@
end
EOF
end

it "handles ivars" do
set_file_contents <<-EOF
@variable.nil? ? do_something : do_something_else
EOF

split

assert_file_contents <<-EOF
if @variable.nil?
do_something
else
do_something_else
end
EOF

join

assert_file_contents <<-EOF
@variable.nil? ? do_something : do_something_else
EOF
end
end

describe "when-then" do
Expand Down

0 comments on commit 1c0f6a6

Please sign in to comment.