Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
ruby_coding_convention

ruby_coding_convention

Ratings: (0)|Views: 50 |Likes:
Published by Jesse Cai

More info:

Published by: Jesse Cai on Sep 23, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/09/2014

pdf

text

original

RubyCodingConvention
(DRAFT VERSION: 2001/11/01)
File Names
Directory and File names and Suffixes
Ruby source code
file/directory name is lower case class/module name with suffix '.rb'.

ex.
Foo class => foo.rb
Bar module => bar.rb
FooBar class => foobar.rb (Normal Rule)

foo_bar.rb (Rails Rule)
Foo::Bar class => foo/bar.rb
Libraries*1

non-standard multiple files required by a script should be in one directory, and they should
be installed to the standard site-ruby directory or a script's library directory.
don't use a current directory for libraries --- it is dangerous. since the directory in which
script exists can not be specified portably, it is also not suited for libraries.

File Organization

\u2022 require (if necessary)
\u2022 include (if necessary)
\u2022 classes and modules definition

\u2022 main
\u2022 testing code(?) using __FILE__ idiom
ex:if __FILE__ == $0
<testcode>
end
Beginning Comment
begin - end style
for file header or footer.

=begin
* Name:
* Description
* Author:
* Date:

* License:
=end
using '#' style
for class/module and method definitions
# using foo bar
## foo bar buz.
#class Foo
# bar.bar.bar.
#class Bar
# constructor of Bar.
#def initialize(bar = nil)
super(bar)
end
def bar
self

end
end
def initialize()

end
end
Indentation
Line length
Max length is about 80 characters.
Wrapping Line
\u2022 Break after comma
\u2022 Break after operator
Comments

Ruby has two comments style: =begin...=end and '#'. You should use =begin...=end for
Documentation Comments, and '#' for both Documentation Comments and Implementation
Comments.

Implementation Comments
Block Comments
# Here is block comment.
## foo, bar, buz.
Single-Line Comments
# this is single line comment.
## this is also single line comment.
Tailing Comments
if a == 2
true
# special case
else
prime?(a)
# work only for odd a
end
Documentation Comments
Header/Footer

=begin
= FooBar library
== What's New?

.....
....
== Installation
.....
....
....
=end
In Class/Module
# .....
# ....
#def foo()
..

Activity (4)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
sm255 liked this
alarue liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->