Displaying 1 result from an estimated 1 matches for "tmphash".
Did you mean:
  thash
  
2006 Mar 16
3
Passing function names from string variables
...uestion, 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?(object.@attr.to_s)
        @tmphash[object.@attr.to_s] = Array.new
      end
      @tmphash[object.@attr.to_s].push(object)
    end
  end
Where the method name is the @attr value.
-- 
Leah Cunningham : d416-585-9971x692 : d416-703...