From: Fredrik Date: 2008-04-29T17:50:05+09:00 Subject: Re: Array#first is not Array#[0] On Apr 29, 5:36 pm, Peņa, Botp wrote: > from: Fredrik [mailto:fredj...@gmail.com] > # include the same text in all my array elements. I just want to have > # some fixed text attached to ANY operations I do with array elements. > > there are other better ways, but i just extended your initial thought/code, > > class MyArray < Array > Array.methods.each do |m| > define_method(m) do > "Here you go: #{super}" > end > end > end > #=>... > > g=MyArray.new [1,2,3] > #=> Here you go: [1, 2, 3] > g[1] > #=> "Here you go: 2" > g[0] > #=> "Here you go: 1" > g.first > #=> 1 > g.last > #=> 3 > g[-1] > #=> "Here you go: 3" > > kind regards -botp But that doesn't work (though I don't understand why). I want it to always say "Here you go: ...", no matter how I retrieve an element out of the array.