Guest User

Untitled

a guest
Apr 26th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. class Array
  2. def evens
  3. get_only :even
  4. end
  5.  
  6. def odds
  7. get_only :odd
  8. end
  9.  
  10.  
  11. def get_only(type)
  12. temp=[]
  13.  
  14. type = (type == :even) ? 0 : 1
  15.  
  16. self.each_index do |x|
  17. if((x & 1)==type)
  18. temp << self[x]
  19. end
  20. end
  21. return temp
  22. end
  23.  
  24. end
Add Comment
Please, Sign In to add comment