1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* doc/syntax/assignment.rdoc (Local Variables and Methods): Fixed

example showing caching of a method's results into a local variable.
  Added not about using an explicit receiver to call a method that
  matches a local variable.  Suggested by markov_twain on twitter.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38901 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2013-01-23 01:35:16 +00:00
parent 98b82acf6f
commit 2784129653
2 changed files with 12 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Wed Jan 23 10:34:47 2013 Eric Hodel <drbrain@segment7.net>
* doc/syntax/assignment.rdoc (Local Variables and Methods): Fixed
example showing caching of a method's results into a local variable.
Added not about using an explicit receiver to call a method that
matches a local variable. Suggested by markov_twain on twitter.
Wed Jan 23 10:20:08 2013 Eric Hodel <drbrain@segment7.net> Wed Jan 23 10:20:08 2013 Eric Hodel <drbrain@segment7.net>
* lib/README: Fixed typo. Patch by Pradeep Sahoo. * lib/README: Fixed typo. Patch by Pradeep Sahoo.

View file

@ -86,11 +86,15 @@ code, for example:
42 # pretend this takes a long time 42 # pretend this takes a long time
end end
big_calculation = big_calculation big_calculation = big_calculation()
Now any reference to +big_calculation+ is considered a local variable and will Now any reference to +big_calculation+ is considered a local variable and will
be cached. To call the method, use <code>self.big_calculation</code>. be cached. To call the method, use <code>self.big_calculation</code>.
You can force a method call by using empty argument parentheses as shown above
or by using an explicit receiver like <code>self.</code>. Using an explicit
receiver may raise a NameError if the method's visibility is not public.
Another commonly confusing case is when using a modifier +if+: Another commonly confusing case is when using a modifier +if+:
p a if a = 0.zero? p a if a = 0.zero?