[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problem with aliasing String#index

Niklas Frykholm

3/15/2005 9:30:00 AM

Aliasing String#index:

"rollo".index(/../, 1)
puts "noalias #{$~}"

class String
alias old_index index

def index(*arg)
ret = old_index(*arg)
puts "inside #{$~}"
return ret
end
end

"winni".index(/../, 3)
puts "outside #{$~}"

gives

noalias ol
inside ni
outside ol

To fully duplicate the functionality of the built-in String#index I need
to transfer $~ from the local scope to the enclosing scope. Is there any
way of doing this?

// Niklas



6 Answers

Florian Gross

3/15/2005 4:41:00 PM

0

Niklas Frykholm wrote:

> To fully duplicate the functionality of the built-in String#index I need
> to transfer $~ from the local scope to the enclosing scope. Is there any
> way of doing this?

There's a solution in the ruby-talk:79283 thread that was posted by
matz, but it's not thread safe. It would be wonderful if we could have a
proper way of doing this...

Niklas Frykholm

3/15/2005 6:06:00 PM

0


>> To fully duplicate the functionality of the built-in String#index I
>> need to transfer $~ from the local scope to the enclosing scope. Is
>> there any way of doing this?
>
>
> There's a solution in the ruby-talk:79283 thread that was posted by
> matz, but it's not thread safe. It would be wonderful if we could have
> a proper way of doing this...

Ah... interesting... but that technique doesn't really work with
String#index, since String#index doesn't take a block.

I think I just have to resign from the idea of making a completely
transparent String wrapper.

But it would be nice if this was resolved. In principle, I think it
should be possible to do the same things from Ruby as from C. I.e. if C
can set a variable $~ in the caller's scope, it should be possible to do
that from Ruby as well.

// Niklas


Patrick Hurley

3/15/2005 10:17:00 PM

0

Thanks for that code, I was lurking reading this thread and have been
wondering all day how to implement that, because of you I will get a
good nights sleep.

pth


On Wed, 16 Mar 2005 05:34:47 +0900, Florian Gross <flgr@ccan.de> wrote:
> Niklas Frykholm wrote:
>
> > Ah... interesting... but that technique doesn't really work with
> > String#index, since String#index doesn't take a block.
> >
> > I think I just have to resign from the idea of making a completely
> > transparent String wrapper.
> >
> > But it would be nice if this was resolved. In principle, I think it
> > should be possible to do the same things from Ruby as from C. I.e. if C
> > can set a variable $~ in the caller's scope, it should be possible to do
> > that from Ruby as well.
>
> Indeed. See attachment, Binding.of_caller.
>
>
>


Niklas Frykholm

3/17/2005 10:14:00 AM

0

Florian Gross wrote:

>> In principle, I think it should be possible to do the same things
>> from Ruby as from C. I.e. if C can set a variable $~ in the caller's
>> scope, it should be possible to do that from Ruby as well.
>
>
> Indeed. See attachment, Binding.of_caller.


Nice. Thanks a lot. I will probably be able to put that to use.

// Niklas



masslibelite

6/23/2008 9:42:00 PM

0

On Jun 23, 4:44 pm, Kmerica...@gmail.com wrote:
> On Jun 23, 4:19 pm, Rangrfan <beezr...@aol.com> wrote:
>
> > Nobody cares about that bullshit.
>
> > Go away
>
> This is the man telling you to go away.  You had better listen, or
> he'll hit you with his purse.
>
> http://www.users.globalnet.co.uk/~rayl...

Nice Aviator Glasses. Bet he has a Members Only jacket for the cool
weather.

rawbylaw

6/24/2008 2:34:00 AM

0

On Jun 23, 4:19 pm, Rangrfan <beezr...@aol.com> wrote:
> On Jun 22, 4:11 pm, rawbylaw <rawby...@aol.com> wrote:
>
>
>
>
>
> >  A provoking personal reflection of a then 18 year old in 1968, to be
> > a part of something greater than himself.  And in the process joins up
> > with the likes of Ralph Abernathy and the Blackstone Rangers.
>
> >  This weekend marks the 40th anniversary of the end of Resurrection
> > City, a shanty town and protest on the Great Mall in Washington, D.C.,
> > that lasted from May through June 1968 when it was razed by federal
> > workers. The goal was to bring together poor people of all backgrounds
> > and put the faces of poverty before the government. It was the last
> > campaign organized by the Rev. Martin Luther King, Jr., before his
> > assassination, and organizers continued with it after his death.
>
> > Dr. Maurice Isserman, now a history professor at Hamilton College, was
> > a high school student at the time. He remembers being a part of the
> > last stand:
>
> >http://weekendamerica.publicradio.org/display/web/2008/06/1......
>
> >  on the shoulders of giants, indeed.
>
> > -jim
>
> Nobody cares about that bullshit.

Ha Ha Ha! you thought i meant those losers who lost to the penguins!
Ha Ha Ha
hockey is stupid. no, it's like bullshit for stupid people. no, it's
like bullshit for stupid people with the initials rangrfan

-jim
>
> Go away.- Hide quoted text -
>
> - Show quoted text -