Is there a way to transform a symbol to a method call? I know it's possible for a String, but not for a symbol. I have this code in conveyance.rb
:
def boats
boats = []
User.all.each{ |u| boats += u.boats}
boats
end
def boats_nb
self.boats.length
end
def cars
cars = []
User.all.each{ |u| cars += u.cars}
cars
end
def cars_nb
self.cars.length
end
I would like to know if there is a means to make a method like that:
def conveyances(:symb)
c = []
User.all.each{ |u| c += u.to_method(:symb) }
c
end
def conveyances_nb(:symb)
User.to_method(:symb).length
end