H
heinous (sent by Nabble.com)
This may be a more generic Ruby question, so I'm going to ask on the Ruby
forum, but I'm trying to figure out if there is a way to pass in the string
value of a variable as the name of a method.
For example, I would like to do something like:
def sort_obj_by_uid(objects,@attr)
@tmparray = Array.new
@tmphash = Hash.new
for object in @objects
if ! @tmphash.has_key?([email protected]_s)
@tmphash[[email protected]_s] = Array.new
end
@tmphash[[email protected]_s].push(object)
end
end
Where the method name is the @attr value.
forum, but I'm trying to figure out if there is a way to pass in the string
value of a variable as the name of a method.
For example, I would like to do something like:
def sort_obj_by_uid(objects,@attr)
@tmparray = Array.new
@tmphash = Hash.new
for object in @objects
if ! @tmphash.has_key?([email protected]_s)
@tmphash[[email protected]_s] = Array.new
end
@tmphash[[email protected]_s].push(object)
end
end
Where the method name is the @attr value.