fork download
  1. def filter(list, params)
  2. result = []
  3. list.each do |element|
  4. case params
  5. when :aho
  6. if element.include?('3') || element.to_i.modulo(3) == 0
  7. result << element
  8. end
  9. when :even
  10. if element.to_i.even?
  11. result << element
  12. end
  13. when :odd
  14. if element.to_i.odd?
  15. result << element
  16. end
  17. else
  18. result << element
  19. end
  20. end
  21. result
  22. end
  23.  
  24. def show_html(list)
  25. puts '<html>'
  26. puts ' <ul>'
  27. list.each do |element|
  28. puts " <ui>#{element}</ui>"
  29. end
  30. puts ' </ul>'
  31. puts '</html>'
  32. end
  33.  
  34. #### :even #####
  35. list = %w(18 22 11 73 91 38 24 17)
  36.  
  37. filtered_list = filter(list, :even)
  38. show_html(filtered_list)
Success #stdin #stdout 0s 8200KB
stdin
Standard input is empty
stdout
<html>
  <ul>
    <ui>18</ui>
    <ui>22</ui>
    <ui>38</ui>
    <ui>24</ui>
  </ul>
</html>