Functional equivalent to oop code in ruby