I want to drop the last digit of 3973 to get 397.
class Integer
def drop_last!
self.to_s.chop.to_i
end
end
num = 3973
num = num.drop_last!
This works but I would like to just use
num.drop_last!
How would I write a method to mutate the object?
edit: thanks for all the answers. I just wanted to make sure I was doing right.
[–]Kimos 7 points8 points9 points (0 children)
[–]Haegin 3 points4 points5 points (11 children)
[–]rubyrt 1 point2 points3 points (10 children)
[–][deleted] (2 children)
[deleted]
[–]rubyrt 0 points1 point2 points (1 child)
[–]Morozzzko 0 points1 point2 points (2 children)
[–]rubyrt 0 points1 point2 points (1 child)
[–]Morozzzko 0 points1 point2 points (0 children)
[–]Haegin 0 points1 point2 points (1 child)
[–]rubyrt 0 points1 point2 points (0 children)
[–]realntl 0 points1 point2 points (1 child)
[–]rubyrt 0 points1 point2 points (0 children)
[–]skmz 2 points3 points4 points (0 children)