Devin Mullins wrote:
> dave wrote:
>
>> list.delete_if(){|obj|  # the list is an array of objects
>>  delete = false        # delete the obj from the list
>>  @tokens.each{|t|      # tockens is the splitted query
>>    if (! delete)
>>      @func_signs.each_key(){|k|
>>        if (t =~ k)
>>          # the calles function split the tocken and
>>          # return true if the obj satisfies this part of tocken
>>          delete = (! send(@func_signs[k], obj, t))
>>        end
>>      }
>>    end
>>  }
>>  delete
>> }
>>
>>
> I didn't test this, so don't assume it works...
>
> list.delete_if{|obj|
>   @tokens.any? {|t|
>     @func_signs.any? {|k,v|
>         (t =~ k) && (!send(v, obj, t))
>       }
>   }
> }

I think that's as good as it can get with the current knowledge.
Depending on the distribution of data in @tokens and @func_signs one might
want to reorder the nesting to reduce the overall number of operations but
other than that this seems quite optimal.

> Not sure if that was what you were looking for...
>
> Questions?
>
> Actually, I've got one. If you do,
> @func_signs.any? {|kv|
>    ...
> }
>
> Ruby knows to pass the key and value as a single argument - the Array
> [k,v] - instead of as the two arguments k and v. How? Can I write my
> own code to do the same?

>> def test() yield [1,2] end
=> nil
>> test {|a| p a}
[1, 2]
=> nil
>> test {|a,b| p a, b}
1
2
=> nil

Kind regards

    robert