fun with splats

Discussion in 'Ruby' started by Martin DeMello, Oct 2, 2005.

  1. class A
    include Enumerable

    def each
    yield :foo
    yield :bar
    yield :baz
    end
    end

    a = A.new
    b = *a #=> [:foo, :bar, :baz]

    (Enumerable defines a to_a, and * works with anything that has to_a
    defined).

    martin
     
    Martin DeMello, Oct 2, 2005
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
Loading...