rewriting hook in ruby