implement BP in ruby