diff options
Diffstat (limited to 'sample/find_comments.rb')
-rw-r--r-- | sample/find_comments.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sample/find_comments.rb b/sample/find_comments.rb new file mode 100644 index 0000000000..2468444210 --- /dev/null +++ b/sample/find_comments.rb @@ -0,0 +1,22 @@ +# This script finds all of the comments within a given source file. + +require "prism" + +Prism.parse_comments(DATA.read).each do |comment| + puts comment.inspect + puts comment.slice +end + +# => +# #<Prism::InlineComment @location=#<Prism::Location @start_offset=0 @length=42 start_line=1>> +# # This is documentation for the Foo class. +# #<Prism::InlineComment @location=#<Prism::Location @start_offset=55 @length=43 start_line=3>> +# # This is documentation for the bar method. + +__END__ +# This is documentation for the Foo class. +class Foo + # This is documentation for the bar method. + def bar + end +end |