CommentCollector

Get source code comments of Ruby.

require RUBY_VERSION >= '2.6.0'

Installation

Or install it yourself as:

$ gem install comment_collector

Usage

example.rb

# class comment
# this is sample
class Foo
  BAR = 'hello' # string

  # method
  def say
    'hi'
  end
end

=begin
multi line
commens
=end

comment.rb

require 'comment_collector'

comments = CommentCollector.get(File.read('example.rb'))

puts '=' * 20

comments.each do |comment|
  puts comment.value
  puts '=' * 20
end

result

$ ruby comment.rb
====================
# class comment
# this is sample
====================
# string
====================
# method
====================
=begin
multi line
commens
=end
====================

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the CommentCollector project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.