https://github.com/dannyben/getcomments
Extract Comments from Ruby Code
https://github.com/dannyben/getcomments
comments documentation gem ruby
Last synced: 10 months ago
JSON representation
Extract Comments from Ruby Code
- Host: GitHub
- URL: https://github.com/dannyben/getcomments
- Owner: DannyBen
- License: mit
- Created: 2017-03-04T12:30:23.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-04-09T14:08:42.000Z (about 3 years ago)
- Last Synced: 2025-07-27T19:02:43.976Z (11 months ago)
- Topics: comments, documentation, gem, ruby
- Language: Ruby
- Size: 26.4 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
GetComments - Extract Comments from Ruby Code
==================================================
This library provides an easy way to extract comments from a ruby source file.
Install
--------------------------------------------------
```
$ gem install getcomments
```
Or with bundler:
```
gem 'getcomments'
```
Usage
--------------------------------------------------
Get comments from a file:
```ruby
# GetComments.from_file
require 'getcomments'
comments = GetComments.from_file 'spec/fixtures/minimal.rb'
comments.each do |key, value|
puts "#{key}: #{value}"
end
#=> module TestModule: Module comment
#=> class TestClass: Class comment
#=> attr_reader :some_attr: Attribute comment
#=> def some_method: Method comment
```
Get comments from a string:
```ruby
# GetComments.from_string
code = <<-EOF
# This function just sits here
def the_function
end
EOF
comments = GetComments.from_string code
comments.each do |key, value|
puts "#{key}: #{value}"
end
#=> def the_function: This function just sits here
```