[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: documentation as source

Peña, Botp

10/20/2004 4:08:00 AM


> # # This creates a Regexp which will match 3 "foo"s.
> # re = Regexp::English.literal("foo" * 3)
> # re.match("foofoofoo")[0] # => "foofoofoo"
>

many times, I have multi-# on a line on my code. Blame me lazy and my editor
:-)

is it possible to put (Example) tags? =)

# #Example: This creates a Regexp which will match 3 "foo"s.
# re = Regexp::English.literal("foo" * 3)
# re.match("foofoofoo")[0] # => "foofoofoo"
# #EndExample <-- this would be optional if it hits another #Example

indents not needed of course.

kind regards -botp


2 Answers

T. Onoma

10/20/2004 5:05:00 AM

0

On Wednesday 20 October 2004 12:07 am, "Peña, Botp" wrote:
| > # # This creates a Regexp which will match 3 "foo"s.
| > # re = Regexp::English.literal("foo" * 3)
| > # re.match("foofoofoo")[0] # => "foofoofoo"
|
| many times, I have multi-# on a line on my code. Blame me lazy and my
| editor
|
| :-)

At least you write comments! Me the L:)

| is it possible to put (Example) tags? =)
|
| # #Example: This creates a Regexp which will match 3 "foo"s.
| # re = Regexp::English.literal("foo" * 3)
| # re.match("foofoofoo")[0] # => "foofoofoo"
| # #EndExample <-- this would be optional if it hits another #Example
|
| indents not needed of course.

In that case there is always markup:

# <example>
# # This creates a Regexp which will match 3 "foo"s.
# re = Regexp::English.literal("foo" * 3)
# re.match("foofoofoo")[0] # => "foofoofoo"
# </example>

But has any one considered YAML? I find myself using YAML style in my comments
sometimes (I use YAML lots) then have to go back and adjust for RDoc.

# - !example |
# # This creates a Regexp which will match 3 "foo"s.
# re = Regexp::English.literal("foo" * 3)
# re.match("foofoofoo")[0] # => "foofoofoo"

But perhaps too restrictive.

T.



Florian Gross

10/20/2004 10:58:00 AM

0

Peña, Botp wrote:

>> # # This creates a Regexp which will match 3 "foo"s.
>> # re = Regexp::English.literal("foo" * 3)
>> # re.match("foofoofoo")[0] # => "foofoofoo"
>>
> many times, I have multi-# on a line on my code. Blame me lazy and my editor
> :-)

Which is not explicitly bad. But do you also have indented text in your
RDoc documentation? test-extract only looks for sample code in RDoc
documentation which is comments that are directly before a method or
class definition like this:

# Here goes the documentation.
# Here goes the sample code.
def foo; end

But not like this:

def foo
# Just a random comment.
# With something random that is indented.
end

> is it possible to put (Example) tags? =)
>
> # #Example: This creates a Regexp which will match 3 "foo"s.
> # re = Regexp::English.literal("foo" * 3)
> # re.match("foofoofoo")[0] # => "foofoofoo"
> # #EndExample <-- this would be optional if it hits another #Example

See above. Is this really necessary? If I add support for this then I
will need to remove the current rule which is less restrictive.

If we really need such a rule I think I would change it so that it would
match anything that is indented and preceded by optional empty lines and
one of the words "example", "sample", "code".

That would still allow you to write:

# This method doubles an object. The object has to respond to +*+.
# It is used like in this example:
#
# double(10) # => 20
# double("hello") # => "hellohello"
# double("") # => ""
# double([1, 2]) # => [1, 2, 1, 2]
# double(:foo) # raises NoMethodError
def double(obj)
obj * 2
end

> kind regards -botp

More regards,
Florian Gross