Posted By

andyh on 02/07/07


Tagged

ruby


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


Uses for Infinity in Ruby


 / Published in: Ruby
 

  1. Infinity = 1.0/0
  2.  
  3. # a rather useless range
  4. everything = -Infinity..Infinity
  5. puts everything.includes?(5) #-> true
  6.  
  7. # use it for representing an unbounded value
  8. storage_limits => { :demo => 0,
  9. :standard => 250.megabytes,
  10. :expert => 1.gigabyte,
  11. :unlimited => Infinity }
  12.  
  13. if bytes_used < storage_limits[account_level]
  14. # add another file or something
  15. else
  16. # display "out of space" message
  17. end

Report this snippet  

You need to login to post a comment.