[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

simple gsub method

Jack Smith

10/1/2008 8:42:00 PM

I have simplified my method for searching test to the following:

def replacer(a, b)
x = "now is the time for all good men to come to the aid of their
country"
x.gsub(/#{a}/, b)
puts x
end

puts "enter what to replace: "
j = gets
puts "enter replacer word: "
h = gets

replacer(j, h)

Can someone help me determine why gsub can't match my "a" value?

thanks
--
Posted via http://www.ruby-....

18 Answers

Stefano Crocco

10/1/2008 8:46:00 PM

0

Alle Wednesday 01 October 2008, Jack Smith ha scritto:
> I have simplified my method for searching test to the following:
>
> def replacer(a, b)
> x = "now is the time for all good men to come to the aid of their
> country"
> x.gsub(/#{a}/, b)
> puts x
> end
>
> puts "enter what to replace: "
> j = gets
> puts "enter replacer word: "
> h = gets
>
> replacer(j, h)
>
> Can someone help me determine why gsub can't match my "a" value?
>
> thanks

Strings returned by gets end in a newline, which doesn't exist in your string,
so no match happens. To solve this, you can do

j = gets.chomp

and the same for h.

I hope this helps

Stefano


Jack Smith

10/1/2008 8:52:00 PM

0

It does help Stefano as I had forgotton about \n so thanks for that but
my script still does not match on my "a" value even with the chomp
method added.




Stefano Crocco wrote:
> Alle Wednesday 01 October 2008, Jack Smith ha scritto:
>> j = gets
>> puts "enter replacer word: "
>> h = gets
>>
>> replacer(j, h)
>>
>> Can someone help me determine why gsub can't match my "a" value?
>>
>> thanks
>
> Strings returned by gets end in a newline, which doesn't exist in your
> string,
> so no match happens. To solve this, you can do
>
> j = gets.chomp
>
> and the same for h.
>
> I hope this helps
>
> Stefano

--
Posted via http://www.ruby-....

Sebastian Hungerecker

10/1/2008 8:57:00 PM

0

Jack Smith wrote:
> x.gsub(/#{a}/, b)

You don't use the return value of gsub, so it is thrown away and this line
basically does nothing. Calling gsub on x, does not change x (gsub! would).

HTH,
Sebastian
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Jack Smith

10/1/2008 8:57:00 PM

0

I take that back Stefano....you solved it for me!
I forgot to add the x.gsub! ....when I did, my script is working.

thanks a REAL lot for helping me with this!

j


Jack Smith wrote:
> It does help Stefano as I had forgotton about \n so thanks for that but
> my script still does not match on my "a" value even with the chomp
> method added.
>
>
>
>
> Stefano Crocco wrote:
>> Alle Wednesday 01 October 2008, Jack Smith ha scritto:
>>> j = gets
>>> puts "enter replacer word: "
>>> h = gets
>>>
>>> replacer(j, h)
>>>
>>> Can someone help me determine why gsub can't match my "a" value?
>>>
>>> thanks
>>
>> Strings returned by gets end in a newline, which doesn't exist in your
>> string,
>> so no match happens. To solve this, you can do
>>
>> j = gets.chomp
>>
>> and the same for h.
>>
>> I hope this helps
>>
>> Stefano

--
Posted via http://www.ruby-....

Free Lunch

2/22/2012 12:05:00 AM

0

On Mon, 20 Feb 2012 21:35:53 -0800, Jason@nospam.com (Jason) wrote in
alt.talk.creationism:

>In article <2rl5k71siu7mj0i01aogtqgbmt4f9d75e5@4ax.com>, Free Lunch
><lunch@nofreelunch.us> wrote:
>
>> On Sun, 19 Feb 2012 23:49:43 -0800, Jason@nospam.com (Jason) wrote in
>> alt.talk.creationism:
>>
>> >In article
>> ><52eb3329-e66f-4985-9d12-5b706c08fb5e@x19g2000yqh.googlegroups.com>,
>> >Devils Advocaat <mankygoat7@gmail.com> wrote:
>> >
>> >> On Feb 19, 7:48=A0pm, Ja...@nospam.com (Jason) wrote:
>> >> > In article <7lv1k7duip0otmqhbsbctvu1eps2mcv...@4ax.com>, Free Lunch
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > <lu...@nofreelunch.us> wrote:
>> >> > > On Sat, 18 Feb 2012 23:49:55 -0800, Ja...@nospam.com (Jason) wrote in
>> >> > > alt.talk.creationism:
>> >> >
>> >> > > >In article <a4hvj7tfgrlfp8a5ubp3fduujm01djs...@4ax.com>, Free Lunch
>> >> > > ><lu...@nofreelunch.us> wrote:
>> >> >
>> >> > > >> On Sat, 18 Feb 2012 02:55:02 -0800, Ja...@nospam.com (Jason)
>wrote i=
>> >> n
>> >> > > >> alt.talk.creationism:
>> >> >
>> >> > > >> >In article
>> >> > > >>
>><d500ac7d-fb6a-432b-9f7c-82e80eac9...@do4g2000vbb.googlegroups.com>=
>> >> ,
>> >> > > >> >Devils Advocaat <mankygo...@gmail.com> wrote:
>> >> >
>> >> > > >> ...
>> >> >
>> >> > > >> >> But you have insisted constantly that abortion is first
>degree mu=
>> >> rder.
>> >> >
>> >> > > >> >> So how can you say its okay to commit murder?
>> >> >
>> >> > > >> >> You contradict yourself so often it is unbelievable.
>> >> >
>> >> > > >> >Nothing is simple--there are always some exceptions to most things.
>> >> >
>> >> > > >> Do you understand that you are arguing for the laws we have today?
>> >> >
>> >> > > >That's not true. Nearly 50 million unborn babies have been
>killed sinc=
>> >> e
>> >> > > >Roe vs. Wade was handed down 37 years ago. In most of those cases, the
>> >> > > >mother's lives were never in any danger.
>> >> >
>> >> > > I was under the impression that you had said that almost all abortions
>> >> > > should take place during the first trimester and that later abortions
>> >> > > should take place only because of the risk they pose to the mother. The
>> >> > > current law is not much different from that.
>> >> >
>> >> > Good point. That is correct. I hope that as a result of the morning after
>> >> > pill--that most abortion clinics will close down due to the lack of
>> >> > business.
>> >>
>> >> Unlikely.
>> >>
>> >> However there is a simple solution.
>> >>
>> >> The anti-abortionists need only, each one individually, lobby their
>> >> congressman (or woman) to remove abortion-on-demand from the abortion
>> >> legislation.
>> >>
>> >> Simple, isn't it?
>> >>
>> >> Or is it too much hassle?
>> >
>> >My congressmen (mostly all liberals) don't listen to me.
>> >
>> They would be fools to listen to your ideas. Since they are not
>> reactionary Republicans, they probably are not fools.
>
>The real reason they don't listen to me is because I don't give them $100,000.
>
Yes, the GOP is the party of the rich. You would be a fool to vote for a
Republican. Are you as much of a fool as you present yourself to be
here?

Jason

2/22/2012 9:38:00 AM

0

In article <95c8k713t5cteuhtb7s45psa55ovga0u63@4ax.com>, Free Lunch
<lunch@nofreelunch.us> wrote:

> On Tue, 21 Feb 2012 10:03:25 -0800, Jason@nospam.com (Jason) wrote in
> alt.talk.creationism:
>
> >In article <XnsA00048D07D561nomailcomcastnet@216.196.121.131>, Mitchell
> >Holman <nomailcomcast.net> wrote:
> >
> >> Jason@nospam.com (Jason) wrote in
> >> news:Jason-2002122143020001@66-53-211-151.lsan.mdsg-pacwest.com:
> >>
> >> > In article <jpl5k7tq210brf9ocqj1f7cdia86nfrnri@4ax.com>, Free Lunch
> >> > <lunch@nofreelunch.us> wrote:
> >> >
> >> >> On Sun, 19 Feb 2012 23:51:21 -0800, Jason@nospam.com (Jason) wrote in
> >> >> alt.talk.creationism:
> >> >>
> >> >> >In article <sok2k71n25g6j5d7lo6nmu261ig05v1q40@4ax.com>, Free Lunch
> >> >> ><lunch@nofreelunch.us> wrote:
> >> >> >
> >> >> >> On Sun, 19 Feb 2012 11:48:04 -0800, Jason@nospam.com (Jason) wrote
> >> >> >> in alt.talk.creationism:
> >> >> >>
> >> >> >> >In article <7lv1k7duip0otmqhbsbctvu1eps2mcvvae@4ax.com>, Free
> >> >> >> >Lunch <lunch@nofreelunch.us> wrote:
> >> >> >> >
> >> >> >> >> On Sat, 18 Feb 2012 23:49:55 -0800, Jason@nospam.com (Jason)
> >> >> >> >> wrote in alt.talk.creationism:
> >> >> >> >>
> >> >> >> >> >In article <a4hvj7tfgrlfp8a5ubp3fduujm01djsrpf@4ax.com>, Free
> >> >> >> >> >Lunch <lunch@nofreelunch.us> wrote:
> >> >> >> >> >
> >> >> >> >> >> On Sat, 18 Feb 2012 02:55:02 -0800, Jason@nospam.com (Jason)
> >> >> >> >> >> wrote in alt.talk.creationism:
> >> >> >> >> >>
> >> >> >> >> >> >In article
> >> >> >> >> >> ><d500ac7d-fb6a-432b-9f7c-82e80eac93ea@do4g2000vbb.googlegrou
> >> >> >> >> >> >ps.com>, Devils Advocaat <mankygoat7@gmail.com> wrote:
> >> >> >> >> >>
> >> >> >> >> >> ...
> >> >> >> >> >>
> >> >> >> >> >> >> But you have insisted constantly that abortion is first
> >> >> >> >> >> >> degree
> >> >> >murder.
> >> >> >> >> >> >>
> >> >> >> >> >> >> So how can you say its okay to commit murder?
> >> >> >> >> >> >>
> >> >> >> >> >> >> You contradict yourself so often it is unbelievable.
> >> >> >> >> >> >
> >> >> >> >> >> >Nothing is simple--there are always some exceptions to most
> >> >> >> >> >> >things.
> >> >> >> >> >>
> >> >> >> >> >> Do you understand that you are arguing for the laws we have
> >> >> >> >> >> today?
> >> >> >> >> >
> >> >> >> >> >That's not true. Nearly 50 million unborn babies have been
> >> >> >> >> >killed since Roe vs. Wade was handed down 37 years ago. In
> >> >> >> >> >most of those cases, the mother's lives were never in any
> >> >> >> >> >danger.
> >> >> >> >> >
> >> >> >> >> I was under the impression that you had said that almost all
> >> >> >> >> abortions should take place during the first trimester and that
> >> >> >> >> later abortions should take place only because of the risk they
> >> >> >> >> pose to the mother. The current law is not much different from
> >> >> >> >> that.
> >> >> >> >
> >> >> >> >Good point. That is correct. I hope that as a result of the
> >> >> >> >morning after pill--that most abortion clinics will close down
> >> >> >> >due to the lack of business.
> >> >> >> >
> >> >> >> You forget that a large share of the anti-abortion movement, the
> >> >> >> anti-choice movement, want to ban the morning after pill and all
> >> >> >> other forms of birth control. Even Rick Santorum complains about
> >> >> >> it being legal.
> >> >> >
> >> >> >Some of them agree with me since it will mean that it will cause
> >> >> >some abortion clinics to close down and that is a good thing.
> >> >> >
> >> >> Why is that a good thing?
> >> >>
> >> >> Why should women be forced to bring unwanted fetuses to term? Is it
> >> >> because the racists cannot find enough white babies to adopt?
> >> >
> >> > You may want to visit this website:
> >> >
> >> > www.40daysforlife.com
> >> >
> >> > That Christian ministry has been able to close down 16 abortion
> >> > clinics in four years.
> >>
> >>
> >>
> >> Does that include the clinic closed because one of
> >> your fellow Christions shot Dr Tiller in the back as he
> >> sang in church?
> >
> >I don't know. Are you referring to Tiller the Baby Killer?
>
> So you think that murder is just fine if you have demonized the target
> of the murder. Once again you show us that you hate what Jesus taught.

Tiller should not have been murdered. However, I did not shed any tears
when I found out that Tiller the baby killer was dead.


Jason

2/22/2012 9:39:00 AM

0

In article <h3c8k7p712bs5531g7nrp3q6tifen5lv29@4ax.com>, Free Lunch
<lunch@nofreelunch.us> wrote:

> On Mon, 20 Feb 2012 21:43:02 -0800, Jason@nospam.com (Jason) wrote in
> alt.talk.creationism:
>
> >In article <jpl5k7tq210brf9ocqj1f7cdia86nfrnri@4ax.com>, Free Lunch
> ><lunch@nofreelunch.us> wrote:
> >
> >> On Sun, 19 Feb 2012 23:51:21 -0800, Jason@nospam.com (Jason) wrote in
> >> alt.talk.creationism:
> >>
> >> >In article <sok2k71n25g6j5d7lo6nmu261ig05v1q40@4ax.com>, Free Lunch
> >> ><lunch@nofreelunch.us> wrote:
> >> >
> >> >> On Sun, 19 Feb 2012 11:48:04 -0800, Jason@nospam.com (Jason) wrote in
> >> >> alt.talk.creationism:
> >> >>
> >> >> >In article <7lv1k7duip0otmqhbsbctvu1eps2mcvvae@4ax.com>, Free Lunch
> >> >> ><lunch@nofreelunch.us> wrote:
> >> >> >
> >> >> >> On Sat, 18 Feb 2012 23:49:55 -0800, Jason@nospam.com (Jason) wrote in
> >> >> >> alt.talk.creationism:
> >> >> >>
> >> >> >> >In article <a4hvj7tfgrlfp8a5ubp3fduujm01djsrpf@4ax.com>, Free Lunch
> >> >> >> ><lunch@nofreelunch.us> wrote:
> >> >> >> >
> >> >> >> >> On Sat, 18 Feb 2012 02:55:02 -0800, Jason@nospam.com (Jason)
wrote in
> >> >> >> >> alt.talk.creationism:
> >> >> >> >>
> >> >> >> >> >In article
> >> >> >> >>
><d500ac7d-fb6a-432b-9f7c-82e80eac93ea@do4g2000vbb.googlegroups.com>,
> >> >> >> >> >Devils Advocaat <mankygoat7@gmail.com> wrote:
> >> >> >> >>
> >> >> >> >> ...
> >> >> >> >>
> >> >> >> >> >> But you have insisted constantly that abortion is first degree
> >> >murder.
> >> >> >> >> >>
> >> >> >> >> >> So how can you say its okay to commit murder?
> >> >> >> >> >>
> >> >> >> >> >> You contradict yourself so often it is unbelievable.
> >> >> >> >> >
> >> >> >> >> >Nothing is simple--there are always some exceptions to most
things.
> >> >> >> >>
> >> >> >> >> Do you understand that you are arguing for the laws we have today?
> >> >> >> >
> >> >> >> >That's not true. Nearly 50 million unborn babies have been
killed since
> >> >> >> >Roe vs. Wade was handed down 37 years ago. In most of those
cases, the
> >> >> >> >mother's lives were never in any danger.
> >> >> >> >
> >> >> >> I was under the impression that you had said that almost all
abortions
> >> >> >> should take place during the first trimester and that later abortions
> >> >> >> should take place only because of the risk they pose to the
mother. The
> >> >> >> current law is not much different from that.
> >> >> >
> >> >> >Good point. That is correct. I hope that as a result of the
morning after
> >> >> >pill--that most abortion clinics will close down due to the lack of
> >> >> >business.
> >> >> >
> >> >> You forget that a large share of the anti-abortion movement, the
> >> >> anti-choice movement, want to ban the morning after pill and all other
> >> >> forms of birth control. Even Rick Santorum complains about it being
> >> >> legal.
> >> >
> >> >Some of them agree with me since it will mean that it will cause some
> >> >abortion clinics to close down and that is a good thing.
> >> >
> >> Why is that a good thing?
> >>
> >> Why should women be forced to bring unwanted fetuses to term? Is it
> >> because the racists cannot find enough white babies to adopt?
> >
> >You may want to visit this website:
> >
> >www.40daysforlife.com
> >
> >That Christian ministry has been able to close down 16 abortion clinics in
> >four years. They have also caused 53 abortion industry employees to leave
> >their jobs.
>
> What happened to the unwanted babies?
>
> Do you care?
>
> The GOP certainly does not.

The social services department can handle those unwanted babies and help
to get them adopted.


tirebiter

2/22/2012 4:06:00 PM

0

On Feb 22, 4:37 am, Ja...@nospam.com (Jason) wrote:
> In article <95c8k713t5cteuhtb7s45psa55ovga0...@4ax.com>, Free Lunch
>
>
>
> > >>     Does that include the clinic closed because one of
> > >> your fellow Christions shot Dr Tiller in the back as he
> > >> sang in church?
>
> > >I don't know. Are you referring to Tiller the Baby Killer?
>
> > So you think that murder is just fine if you have demonized the target
> > of the murder. Once again you show us that you hate what Jesus taught.
>
> Tiller should not have been murdered. However, I did not shed any tears
> when I found out that Tiller the baby killer was dead.

More proof that you are a horrible person. Why do you display that so
proudly?

---
a.a. #2273

tirebiter

2/22/2012 4:07:00 PM

0

On Feb 22, 4:39 am, Ja...@nospam.com (Jason) wrote:
> In article <h3c8k7p712bs5531g7nrp3q6tifen5l...@4ax.com>, Free Lunch
>
>
>
> > What happened to the unwanted babies?
>
> > Do you care?
>
> > The GOP certainly does not.
>
> The social services department can handle those unwanted babies and help
> to get them adopted.

Are you advocating for large invasive socialist based government? You
hypocrite.

---
a.a. #2273

David Fritzinger

2/22/2012 6:22:00 PM

0

In article
<ad4b6054-0fba-4332-bf7c-e2738fc8659c@l1g2000vbc.googlegroups.com>,
tirebiter <dontspamme666@bigfoot.com> wrote:

> On Feb 22, 4:39 am, Ja...@nospam.com (Jason) wrote:
> > In article <h3c8k7p712bs5531g7nrp3q6tifen5l...@4ax.com>, Free Lunch
> >
> >
> >
> > > What happened to the unwanted babies?
> >
> > > Do you care?
> >
> > > The GOP certainly does not.
> >
> > The social services department can handle those unwanted babies and help
> > to get them adopted.
>
> Are you advocating for large invasive socialist based government? You
> hypocrite.
>
> ---
> a.a. #2273

What is funny (well, actually sad) is that social services that Jason
says will handle the unwanted children are precisely the things that his
Republican heroes want to cut. Go figure...