From 3acb37f5a27562730072b96c81d32add8713a59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 14 Dec 2016 17:52:43 +0100 Subject: [PATCH] Avoid choking on Ruby 2.3 heredoc syntax Ruby 2.3 introduces `<<~` heredoc syntax, but when ripper-tags is ran on Ruby 2.2, it acts weirdly around the heredoc, passing a `:~` symbol to `on_stmts_add`. This change avoids Ruby chrashing when encountering this syntax which it doesn't understand. --- lib/ripper-tags/parser.rb | 1 + test/test_ripper_tags.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/ripper-tags/parser.rb b/lib/ripper-tags/parser.rb index 192c598..6c2d108 100644 --- a/lib/ripper-tags/parser.rb +++ b/lib/ripper-tags/parser.rb @@ -17,6 +17,7 @@ def on_#{event}(tok) end def on_stmts_add(first, *rest) + return if first == :~ (first || []) + rest.compact end diff --git a/test/test_ripper_tags.rb b/test/test_ripper_tags.rb index 9a93760..17979a5 100644 --- a/test/test_ripper_tags.rb +++ b/test/test_ripper_tags.rb @@ -434,4 +434,20 @@ class A assert_equal 1, tags.size assert_equal 'A', tags[0][:name] end + + def test_heredoc + tags = extract(<<-EOC) + def foo + puts "hello", <<~EOF + world + EOF + end + + def bar; end + EOC + + assert_equal 2, tags.size + assert_equal 'foo', tags[0][:name] + assert_equal 'bar', tags[1][:name] + end end