`twice` implementation in ruby