text stringlengths 0 444 |
|---|
---- |
# bad |
=begin |
comment line |
another comment line |
=end |
# good |
# comment line |
# another comment line |
---- |
.From Perl's POD to RD |
**** |
This is not really a block comment syntax, but more of |
an attempt to emulate Perl's https://perldoc.perl.org/perlpod.html[POD] documentation system. |
There's an https://github.com/uwabami/rdtool[rdtool] for Ruby that's pretty similar to POD. |
Basically `rdtool` scans a file for `=begin` and `=end` pairs, and extracts |
the text between them all. This text is assumed to be documentation in |
https://github.com/uwabami/rdtool/blob/master/doc/rd-draft.rd[RD format]. |
You can read more about it |
https://ruby-doc.com/docs/ProgrammingRuby/html/rdtool.html[here]. |
RD predated the rise of RDoc and YARD and was effectively obsoleted by them.footnote:[According to this https://en.wikipedia.org/wiki/Ruby_Document_format[Wikipedia article] the format used to be popular until the early 2000s when it was superseded by RDoc.] |
**** |
== Gemfile and Gemspec |
=== No `RUBY_VERSION` in the gemspec [[no-ruby-version-in-the-gemspec]] |
The gemspec should not contain `RUBY_VERSION` as a condition to switch dependencies. |
`RUBY_VERSION` is determined by `rake release`, so users may end up with wrong dependency. |
[source,ruby] |
---- |
# bad |
Gem::Specification.new do |s| |
if RUBY_VERSION >= '2.5' |
s.add_runtime_dependency 'gem_a' |
else |
s.add_runtime_dependency 'gem_b' |
end |
end |
---- |
Fix by either: |
* Post-install messages. |
* Add both gems as dependency (if permissible). |
* If development dependencies, move to Gemfile. |
== Misc |
=== No Flip-flops [[no-flip-flops]] |
Avoid the use of flip-flops. |
=== No non-`nil` Checks [[no-non-nil-checks]] |
Don't do explicit non-`nil` checks unless you're dealing with boolean values. |
[source,ruby] |
---- |
# bad |
do_something if !something.nil? |
do_something if something != nil |
# good |
do_something if something |
# good - dealing with a boolean |
def value_set? |
!@some_boolean.nil? |
end |
---- |
=== Global Input/Output Streams [[global-stdout]] |
Use `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`. |
`STDOUT/STDERR/STDIN` are constants, and while you can actually reassign (possibly to redirect some stream) constants in Ruby, you'll get an interpreter warning if you do so. |
[source,ruby] |
---- |
# bad |
STDOUT.puts('hello') |
hash = { out: STDOUT, key: value } |
def m(out = STDOUT) |
out.puts('hello') |
end |
# good |
$stdout.puts('hello') |
hash = { out: $stdout, key: value } |
def m(out = $stdout) |
out.puts('hello') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.