Hi Everyone,
I am very new to Ruby but have overcome quite a few problems on the road
already. However, this one seems to be a tough nut to crack for me, so
any help from you would be highly appreciated. OK. So here is what I am
trying to achieve:
EXAMPLE:
array_of_objects = [obj1,obj2,obj3]
def my_method(arg1,arg2)
arg1.each { |object|
puts object.arg2 #want to substitute arg2
}
end
my_method(array_of_objects,‘desired property’)
END EXAMPLE
#want to substitue arg2 with the property/method call given as input
when calling the method
#The object property can be for instance the length or width or any
method you can call on the object in the array_of_objects,
#but how can I substitute this function, or method call into the method
call for the object?
#I am guessing a proc or a lambda or block is what I an looking for, but
I cannot seem to get it to work…
#would be very good as one function then can return any properties,
instead of having to make one function for each property.
#Would be very grateful if anyone could help me with this as I am very
new to ruby