Check to see if a num is Negative

if difference < 0
  # ...
end

You should seriously consider reading a Ruby (not Rails) tutorial.
Many things should become much more clear to you as a result.

Hey Gents,

Is there anything that will allow me to determine if a variable is a
positive or negative number??

I have this line:
difference = list_stripes.planned.to_i - list_stripes.spent.to_i

And then I want to check difference to see if it is positive or negative
value.

if difference < 0
  # ...
end

You should seriously consider reading a Ruby (not Rails) tutorial.
Many things should become much more clear to you as a result.

I'll second jdl, but also point out the comparison method <=> which returns -1, 0, or 1 depending on whether the left-hand-side is less-than, equal-to, or greater-than the right-hand-side.

There's also .nonzero? which is false (nil, actually) when the receiver is 0, or the value of the receiver otherwise.

5 <=> 3

=> 1

5 <=> 9

=> -1

5 <=> 5

=> 0

4.nonzero?

=> 4

-5.nonzero?

=> -5

0.nonzero?

=> nil

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

Well, I think the OP needs basic programming lessons, THEN Ruby lessons, THEN Rails.

Are you guys serious? A string conversion and a regexp just to see
whether a number is less than zero or not?

Chris

I think someone needs to turn on his sarcasm detector.

Jason

Oh, come on. Give ''em a break.

Class Numeric
   def negative?
      self < 0
   end
end