Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Array
- def sum
- ans = 0
- for i in self
- ans += i
- end
- ans
- end
- def square
- ans = []
- for i in self
- ans << i * i
- end
- ans
- end
- def square!
- ans = []
- for i in 1 .. length - 1
- self[i] = self[i] * self[i]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment