class Bmi
Public Class Methods
calc(*args)
click to toggle source
# File bmi.rb, line 2 def self.calc(*args) case args.size when 2 htc=args[0] kg=args[1] m=htc.to_f/100 h2=m.to_f*m bmi=kg.to_f/h2 f_bmi = bmi.floor diff=bmi.to_f-f_bmi.to_f diff=diff.to_f*10 diff=diff.round if (diff == 10) #Need to bump up the whole thing instead f_bmi += 1; diff = 0; end bmi = f_bmi + diff.to_f/10; when 3 w=args[0] v=args[1] u=args[2] i = (v.to_f * 12).to_i + u.to_f; ins=i lbs=w h2=ins.to_f*ins.to_f bmi=(lbs.to_f/h2)*703 f_bmi=bmi.floor diff=bmi-f_bmi diff=diff*10 diff=diff.round if (diff == 10) # Need to bump up the whole thing instead f_bmi += 1; diff = 0; end bmi = f_bmi + diff.to_f/10; end end