Add ref.; event handling in Ruby