Uses for Infinity in Ruby


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.