rewrite stock in ruby