Difference between Class.new and construct literals

Hi,

Sorry if the following is such a n00b question.
But I just don't get 1 thing.

What is the difference between

a = Array.new

and

a = []

Look at the following code:

class Class
    alias oldNew new

    def new(*args)
        puts 'Creating new ' + self.to_s
        oldNew(*args)
    end
end

class Array
    alias oldInit initialize

    def initialize(*args)
        puts 'Initializing Array'
        oldInit(*args)
    end
end

# this works as expected
a = Array.new

# this doesn't work
b = [1,2,3,4]

How is the Array constructed when using literals as in `a = []` ? Why
hasn't the overriding of those 2 methods worked ?

For better or worse, you can't overide the literal contructor AFAIK.

T.

OK, but what I'd like to know, is why

bonefry wrote:

OK, but what I'd like to know, is why

My guess is that the interpreter takes [1,2,3] and interprets it as some hard-coded C call.

Devin