[Paul Brannan] > When I write code that does this: # Example simplified class Foo def self.[](*args) p args end X = self X[1] X[1] end > Then I get output like this: > > ruby -w bracket.rb > bracket.rb:11: warning: useless use of [] in void context Ruby warns when it sees something useless. Array lookups are usually useless unless you do something with the looked up value (store it in a variable or call a function with it). Therefore ruby warns you when you use an array lookup and don't do anything with the value. However, you have overriden the [] operator to _do_ something useful. But ruby doesn't know about that, so it still gives the warning. Perhaps you shouldn't override [] to do useful things... on the other hand, the Proc class in ruby does that, so you are in good company. > However, if I take out the second X[ :foo, ... ] line, then I do not get > the warning. The last line in a class definition is the return value of that definition, so it is always useful. That is why you do not get a warning for the last line. > 1) Why do I get this warning? See above. > 2) Is this a bug? Perhaps. Its matz' call :) > 3) Is there a workaround until this can be fixed (or if it will be fixed)? Use another method than []... unless you are doing array lookup or array construction there is no need to call the method []. Fixing this is a bit difficult. The warning is flagged at parse time and at that time, ruby doesn't know whether [] is overridden or not. And knowing whether it is overridden to do something "useful" is nearly impossible. One option could be to remove the warning completely. Ruby warns about other methods too, such as '+'. In theory they could be overridden to do useful things, but that would be pathological and deserves a warning. But since [] is used by proc it should perhaps not have a warning? I'm not sure... // Niklas