improved ruby's snipet