I need a function which returns/prints the sign on an integer. So far I came up with this:
def extract_sign(integer) integer >= 0 ? \'+\' : \'-\' end >
Here is a simple way to do it:
x = -3 "++-"[x <=> 0] # => "-" x = 0 "++-"[x <=> 0] # => "+" x = 3 "++-"[x <=> 0] # => "+"
or
x = -3 "±+-"[x <=> 0] # => "-" x = 0 "±+-"[x <=> 0] # => "±" x = 3 "±+-"[x <=> 0] # => "+"