From: Richard Conroy Date: 2007-11-21T21:45:15+09:00 Subject: Re: porting java methods to ruby On Nov 21, 2007 10:25 AM, Martin Durai wrote: > Hi peter, > > i have attached my java code which i have to port to ruby. could you > help me with this I would refactor that code before you consider porting it to anything. Theres a lot of external dependencies and a lot of unsafe constructs. That single function uses the following instance members: usePC eventType pcStart pcEnd posStart posEnd pc buf getText You are also not doing a lot of input value checking, and the function is very non-DRY. All of the return values are side effects of the method, defined elsewhere. The position holder (the function argument) should be a class. However its par for the course in Java really. However even in Java you would find that function very difficult to unit test without complex mocking. You would never write a Ruby function that behaved like that. You would break up the responsibilities of the function into individual pieces (functions), then take advantage of Ruby's better literal syntax and conditionals to clear up the messy conditionals. (The Ruby switch statement is a thing of beauty).