replace the code from objc to ruby