123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Example

Relationships & Source Files
Namespace Children
Modules:
Classes:
Inherits: Object
Defined in: doc/rdoc/example.rb

Overview

Example provides example Ruby code objects for demonstrating RDoc’s documentation capabilities.

This class is used by:

  • bin/console for interactive exploration of RDoc objects

  • Testing cross-reference link generation

  • Demonstrating Ruby-specific directives like :call-seq:, :args:, :yields:

For comprehensive RDoc markup documentation, see doc/markup_reference/rdoc.rdoc.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.singleton_method_example(foo, bar)

Example singleton method.

[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 25

def self.singleton_method_example(foo, bar); end

Instance Attribute Details

#aliased_attribute (readonly)

[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 40

alias aliased_attribute example_attribute

#example_attribute (rw) Also known as: #aliased_attribute

Example attribute.

[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 38

attr_accessor :example_attribute

Instance Method Details

#aliased_method(foo, bar)

[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 35

alias aliased_method instance_method_example

#args_example(foo, bar)

The :args: directive overrides the actual arguments found in the Ruby code.

The actual signature is args_example(foo, bar), but the directive makes it appear as args_example(baz).

[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 76

def args_example(foo, bar) # :args: baz
  nil
end

#call_seq_example(foo, bar) #be(anything) ⇒ bar #anything(more) ⇒ baz, bat

The :call-seq: directive overrides the actual calling sequence found in the Ruby code.

  • It can specify anything at all.

  • It can have multiple calling sequences.

Note that the “arrow” is two characters, hyphen and right angle-bracket, which is made into a single character in the HTML.

Here is the :call-seq: directive given for this method:

:call-seq:
  call_seq_example(foo, bar)
  Can be anything -> bar
  Also anything more -> baz or bat
[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 66

def call_seq_example
  nil
end

#derived_docs_example(foo, bar) {|'baz'| ... }

This method is documented only by RDoc’s derived documentation, except for these comments.

RDoc automatically extracts:

  • Method name

  • Arguments

  • Yielded values

Yields:

  • ('baz')
[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 98

def derived_docs_example(foo, bar)
  yield 'baz'
end

#instance_method_example(foo, bar) {|'baz'| ... } Also known as: #aliased_method

Example instance method.

This method demonstrates how RDoc documents instance methods, including arguments and yield parameters.

Yields:

  • ('baz')
[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 31

def instance_method_example(foo, bar)
  yield 'baz'
end

#yields_example(foo, bar) {|'baz'| ... }

The :yields: directive overrides the actual yield found in the Ruby code.

The actual yield is ‘baz’, but the directive makes it appear as ‘bat’.

Yields:

  • ('baz')
[ GitHub ]

  
# File 'doc/rdoc/example.rb', line 86

def yields_example(foo, bar) # :yields: 'bat'
  yield 'baz'
end