Most efficient way to extract arguments from String in Ruby
===

I would like to extract some information from a string in Ruby by only reading the String once (O(n) time complexity).

Here is an example:

The string looks like this: `-location here -time 7:30pm -activity biking`

I have a Ruby object I want to populate with this info. All the keywords are known, and they are all optional.

    def ActivityInfo
      _attr_reader_ :location, :time, :activity
    
      def initialize(str)
        @location, @time, @activity = DEFAULT_LOCATION, DEFAULT_TIME, DEFAULT_ACTIVITY
    
        # Here is how I was planning on implementing this
        current_string = ""
        next_parameter = nil # A reference to keep track of which parameter the current string is refering to
        words = str.split
        while !str.empty?
          word = str.shift
          case word
          when "-location"
            if !next_parameter.nil?
              next_parameter.parameter = current_string # Set the parameter value to the current_string
              current_string = ""
            else
            next_parameter = @location
          when "-time"
            if !next_parameter.nil?
              next_parameter.parameter = current_string
              current_string = ""
            else
            next_parameter = @time
          when "-activity"
            if !next_parameter.nil?
              next_parameter.parameter = current_string
              current_string = ""
            else
            next_parameter = @time
          else
            if !current_string.empty?
              current_string += " "
            end
            current_string += word
          end
        end
      end   
    end

So basically I just don't know how to make a variable be the reference of another variable or method, so that I can then set it to a specific value. Or maybe there is just another more efficient way to achieve this?

Thanks!