From: Sandro Paganotti Date: 2008-04-29T17:51:46+09:00 Subject: Re: Array#first is not Array#[0] Maybe is better using instance_methods instead class MyArray < Array Array.instance_methods.each do |m| define_method(m) do "Here you go: #{super}" end end end irb(main):033:0> g=MyArray.new [1,2,3] => Here you go: [1, 2, 3] irb(main):034:0> g.first => "Here you go: 1" irb(main):035:0> On Tue, Apr 29, 2008 at 8:36 AM, Peņa, Botp wrote: > from: Fredrik [mailto:fredjoha@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 > > > -- Go outside! The graphics are amazing!