Yes !
I didn't think about using instance_eval this way and define my own
"with" method... I'm still not confortable with metaprogramming ;-)

Thank you both,
Come

On 23 ao, 10:23, Gregor Kopp <g... / cutcopy.com> wrote:
> Pe wrote:
> > some simple example,
>
> > irb(main):014:0> def with x, &block
> > irb(main):015:1>    x.instance_eval &block
> > irb(main):016:1> end
> > => nil
> > irb(main):017:0> with "test" do
> > irb(main):018:1*   p length
> > irb(main):019:1>   p upcase
> > irb(main):020:1>   p capitalize
> > irb(main):021:1>   p self
> > irb(main):022:1> end
> > 4
> > "TEST"
> > "Test"
> > "test"
> > => nil
> > irb(main):023:0>
>
> > kind regards -botp
>
> Another way:
>
> class Object
>    def with &block
>      yield self
>    end
> end
>
> verylongobject = "Hakuna Matata!"
>
> verylongobject.with do |o|
>    puts o #-> Kakuna Matata!
>    puts o.length #-> 14
>    puts o.reverse #-> !atataM anukaH
>    puts o.upcase #-> HAKUNA MATATA!
> end