summaryrefslogtreecommitdiff
path: root/doc/syntax
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-23 01:35:16 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-23 01:35:16 +0000
commit27841296538ece9c149d85da72c9234ad08556d2 (patch)
tree8357a7f69d5ccbb06c1283c2090f790d19be705b /doc/syntax
parent98b82acf6f18176b932b6145bb2bf3a21022a67d (diff)
* 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
Diffstat (limited to 'doc/syntax')
-rw-r--r--doc/syntax/assignment.rdoc6
1 files changed, 5 insertions, 1 deletions
diff --git a/doc/syntax/assignment.rdoc b/doc/syntax/assignment.rdoc
index c371593..7e58622 100644
--- a/doc/syntax/assignment.rdoc
+++ b/doc/syntax/assignment.rdoc
@@ -86,11 +86,15 @@ code, for example:
42 # pretend this takes a long time
end
- big_calculation = big_calculation
+ big_calculation = big_calculation()
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>.
+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+:
p a if a = 0.zero?