John Smith John Smith - 6 months ago 9x
Ruby Question

Create object with methods

I would like to create an object with one simple get method:
I would like to use a valid code that looks somehow like that:

obj = {def people() return @people_arr end}

Whats the shortest code you know to do that? Thanks


You can define a singleton method on that object like:

obj =
obj.define_singleton_method(:your_method) { puts 'this is my awesome method only defined for this object' }