Skip to content

Instantly share code, notes, and snippets.

@naohaq
Created November 28, 2012 03:59
Show Gist options
  • Save naohaq/4158954 to your computer and use it in GitHub Desktop.
Save naohaq/4158954 to your computer and use it in GitHub Desktop.
Unary '-' operator in Ruby
colinux> ruby uminus.rb
a(0) called.
a(-3) called.
c = -3
d = -6
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