Changed the Ruby code as like Java code