fork download
  1. # your code goes here
  2.  
  3. def total(from, to)
  4. result = 0
  5. from.upto(to) do |num|
  6. if block_given?
  7. result += yield(num)
  8. else
  9. result += num
  10. end
  11. end
  12. return result
  13. end
  14.  
  15. p total(1, 10)
  16. p total(1, 10) { |num|
  17. num ** 2
  18. }
  19.  
Success #stdin #stdout 0s 29112KB
stdin
Standard input is empty
stdout
55
385