From: "Peña, Botp" Date: 2008-04-29T18:41:36+09:00 Subject: Re: Array#first is not Array#[0] From: Fredrik [mailto:fredjoha@gmail.com] # I'm sorry, I think I am too vague about what I want to achieve. What I # want is to have is an "array" that behaves exactly like an array # EXCEPT that each element has some text attached to it. Array#size is # not an element but Array#last is an element for example. # Maybe it's not doable in any other way than copying the text into each # element since I would like this text to follow into Array#each, # Array#map and all those methods. ok, then just modify those you want eg, class Array2 < Array %w([] first last).each do |m| define_method(m) do r = super puts "Here you go: #{r}" r end end end #=> ["[]", "first", "last"] a=Array2.new [1,2,3] #=> [1, 2, 3] a[0] Here you go: 1 #=> 1 a.first Here you go: 1 #=> 1 a.size #=> 3 # What I am still thinking about though, is this: # Why on earth is Array#first not calling Array#[0] ??? that would be calling two methods, and would be quite expensive, right? kind regards -botp