>>>>> "S" == Stephen White <steve / deaf.org> writes:

S> I'm guessing the reason is because '<<' is implemented by a local method,
S> whereas "+=" is implemented by another class so that means a couple more
S> bounces around the class hierachy to resolve what to call? Is that right?

pigeon% cat b.rb
#!/usr/bin/ruby
a = File.new("a").read(nil)
table = {}
pattern = /(new|table|end)/
a.scan(pattern) {|i|
   table[i] ||= []   
   table[i] += $~.begin(0)
}
puts table.inspect
pigeon% 

pigeon% b.rb
{["new"]=>[6, 20], ["table"]=>[0], ["end"]=>[10]}
pigeon% 

pigeon% /usr/bin/ruby -v
ruby 1.4.6 (2000-08-16) [i686-linux]
pigeon% 

pigeon% ./ruby b.rb
b.rb:7:in `+': wrong argument type Fixnum (expected Array) (TypeError)
        from b.rb:7
        from b.rb:5:in `scan'
        from b.rb:5
pigeon% 

pigeon% ./ruby -v
ruby 1.6.0 (2000-08-24) [i686-linux]
pigeon% 

 It work with 1.4.6 and 1.6.0 with <<


Guy Decoux