Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Ruby YARD docs, what it mean to wrap a word +example+ with + (plus sign)?

Tags:

ruby

yard

In the official YARD docs, there is the following example:

# @overload set(key, value)
#   Sets a value on key
#   @param key [Symbol] describe key param
#   @param value [Object] describe value param
# @overload set(value)
#   Sets a value on the default key +:foo+
#   @param value [Object] describe value param
def set(*args) end

What special meaning does +:foo+ have when it is wrapped with + on either side? Does +:foo+ have a different meaning from :foo?

like image 312
Bill Mei Avatar asked Nov 25 '17 22:11

Bill Mei


People also ask

Why use yard for Ruby documentation?

Most importantly, it's really easy to do! There are already plugins that support frameworks like RSpec, DataMapper, Sinatra, and support for others are in the works. YARD is the only Ruby documentation tool that supports storing metadata alongside your documentation.

What is the best Ruby documentation tool?

YARD is the only Ruby documentation tool that supports storing metadata alongside your documentation. This metadata can be used to create consistent documentation in any format you wish. YARD also comes with a powerful templating system to quickly modify existing templates.

Does yard automatically generate documentation for my code?

As of version 0.7.0, YARD will automatically pick up on these basic methods if you document them with a docstring. Therefore, simply adding some comments to the code will cause it to generate documentation:

How do I extend yard to support non-standard Ruby syntax?

There are many ways to extend YARD to support non-standard Ruby syntax (DSLs), add new meta-data tags or programmatically access the intermediate metadata and documentation from code. An overview of YARD's full architecture can be found in the Overview document.


1 Answers

It has no meaning to YARD. In fact, YARD doesn't care about markup at all, it simply passes the string through to the output generator tool unprocessed. (With some limited exceptions, e.g. support for references to modules, classes, methods.)

It does, however, have meaning to SimpleMarkup / RDoc (which is one of the output processors YARD supports). +foo+ is RDoc's syntax for code highlighting, i.e. it is equivalent to `foo` in Markdown.

So the difference is that :foo is rendered as ":foo" whereas +:foo+ is rendered as ":foo", assuming that you use SimpleMarkup / RDoc as the output processor. If you use Markdown as the output processor, it doesn't mean anything at all.

like image 101
Jörg W Mittag Avatar answered Nov 15 '22 11:11

Jörg W Mittag