Created
November 28, 2012 03:59
-
-
Save naohaq/4158954 to your computer and use it in GitHub Desktop.
Unary '-' operator in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colinux> ruby uminus.rb | |
a(0) called. | |
a(-3) called. | |
c = -3 | |
d = -6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def a(x=0) | |
STDOUT.printf "a(%s) called.\n", x.inspect | |
return x*2 | |
end | |
b = 3 | |
c = a - b | |
d = a -b | |
STDOUT.printf "c = %s\n", c.inspect | |
STDOUT.printf "d = %s\n", d.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment