ruby-changes:26801
From: drbrain <ko1@a...>
Date: Thu, 17 Jan 2013 08:39:19 +0900 (JST)
Subject: [ruby-changes:26801] drbrain:r38853 (trunk): * doc/syntax/miscellaneous.rdoc: Added documentation for alias, undef,
drbrain 2013-01-17 08:36:46 +0900 (Thu, 17 Jan 2013) New Revision: 38853 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38853 Log: * doc/syntax/miscellaneous.rdoc: Added documentation for alias, undef, BEGIN, END. * doc/syntax/modules_and_classes.rdoc (Constants): Fixed unwrapped paragraph with trailing whitespace. * doc/syntax/modules_and_classes.rdoc (Scope): Added section pointing to alias and undef documentation. * doc/syntax.rdoc: Added link to miscellaneous section. Added files: trunk/doc/syntax/miscellaneous.rdoc Modified files: trunk/ChangeLog trunk/doc/syntax/modules_and_classes.rdoc trunk/doc/syntax.rdoc Index: doc/syntax/miscellaneous.rdoc =================================================================== --- doc/syntax/miscellaneous.rdoc (revision 0) +++ doc/syntax/miscellaneous.rdoc (revision 38853) @@ -0,0 +1,61 @@ https://github.com/ruby/ruby/blob/trunk/doc/syntax/miscellaneous.rdoc#L1 += Miscellaneous Syntax + +== +alias+ + +The +alias+ keyword is most frequently used to alias methods. When aliasing a +method you can use either its name or a symbol: + + alias new_name old_name + alias :new_name :old_name + +For methods, Module#alias_method can often be used instead of +alias+. + +You can also use +alias+ to alias global variables: + + $old = 0 + + alias $new $old + + p $new # prints 0 + +You may use +alias+ in any scope. + +== +undef+ + +The +undef+ keyword prevents the current class from responding to calls to the +named methods. + + undef my_method + +You may use symbols instead of method names: + + undef :my_method + +You may undef multiple methods: + + undef method1, method2 + +You may use +undef+ in any scope. See also Module#undef_method + +== +BEGIN+ and +END+ + ++BEGIN+ defines a block that is run before any other code in the current file. +It is typically used in one-liners with <code>ruby -e</code>. Similarly +END+ +defines a block that is run after any other code. + ++BEGIN+ must appear at top-level and +END+ will issue a warning when you use it +inside a method. + +Here is an example: + + BEGIN { + count = 0 + } + +You must use <code>{</code> and <code>}</code> you may not use +do+ and +end+. + +Here is an example one-liner that adds numbers from standard input or any files +in the argument list: + + ruby -ne 'BEGIN { count = 0 }; END { puts count }; count += gets.to_i' + Property changes on: doc/syntax/miscellaneous.rdoc ___________________________________________________________________ Added: svn:eol-style + LF Index: doc/syntax/modules_and_classes.rdoc =================================================================== --- doc/syntax/modules_and_classes.rdoc (revision 38852) +++ doc/syntax/modules_and_classes.rdoc (revision 38853) @@ -93,8 +93,9 @@ nesting: https://github.com/ruby/ruby/blob/trunk/doc/syntax/modules_and_classes.rdoc#L93 end end -However, if you use <code>::</code> to define <code>A::B</code> without nesting -it inside +A+ a NameError exception will be raised because the nesting does not include +A+: +However, if you use <code>::</code> to define <code>A::B</code> without +nesting it inside +A+ a NameError exception will be raised because the nesting +does not include +A+: module A Z = 1 @@ -193,6 +194,12 @@ The third visibility is +private+. A pr https://github.com/ruby/ruby/blob/trunk/doc/syntax/modules_and_classes.rdoc#L194 receiver, not even +self+. If a private method is called with a receiver a NoMethodError will be raised. +=== +alias+ and +undef+ + +You may also alias or undefine methods, but these operations are not +restricted to modules or classes. See the {miscellaneous syntax +section}[rdoc-ref:syntax/miscellaneous.rdoc] for documentation. + = Classes Every class is also a module, but unlike modules a class may not be mixed-in to Index: doc/syntax.rdoc =================================================================== --- doc/syntax.rdoc (revision 38852) +++ doc/syntax.rdoc (revision 38853) @@ -23,3 +23,6 @@ Exceptions[rdoc-ref:syntax/exceptions.rd https://github.com/ruby/ruby/blob/trunk/doc/syntax.rdoc#L23 Precedence[rdoc-ref:syntax/precedence.rdoc] :: Precedence of ruby operators +Miscellaneous[rdoc-ref:syntax/miscellaneous.rdoc] :: + +alias+, +undef+, +BEGIN+, +END+ + Index: ChangeLog =================================================================== --- ChangeLog (revision 38852) +++ ChangeLog (revision 38853) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jan 17 08:36:04 2013 Eric Hodel <drbrain@s...> + + * doc/syntax/miscellaneous.rdoc: Added documentation for alias, undef, + BEGIN, END. + * doc/syntax/modules_and_classes.rdoc (Constants): Fixed unwrapped + paragraph with trailing whitespace. + * doc/syntax/modules_and_classes.rdoc (Scope): Added section pointing + to alias and undef documentation. + * doc/syntax.rdoc: Added link to miscellaneous section. + Thu Jan 17 07:50:26 2013 Eric Hodel <drbrain@s...> * doc/syntax/control_expressions.rdoc (Flip-Flop): Added a section on -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/