What does << mean in Ruby?

Viewed 97902

I have code:

  def make_all_thumbs(source)
    sizes = ['1000','1100','1200','800','600']
    threads = []
    sizes.each do |s|
      threads << Thread.new(s) {
        create_thumbnail(source+'.png', source+'-'+s+'.png', s)
      }
    end
  end

what does << mean?

8 Answers

Also, since Ruby 2.6, the << method is defined also on Proc.

Proc#<< allows to compose two or more procs.

It means add to the end (append).

a = [1,2,3]
a << 4
a = [1,2,3,4]
Related