[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

puts "\\".gsub("\\", "\\\\"

martinus

4/24/2008 9:54:00 AM

Hello, I have a mini-ruby quiz. Guess what this line of code writes to
the console, then try it for yourself:

puts "\\".gsub("\\", "\\\\")

Why is that so?

Martin
49 Answers

Peña, Botp

4/24/2008 10:01:00 AM

0

From: martinus [mailto:martin.ankerl@gmail.com]=20
# Hello, I have a mini-ruby quiz. Guess what this line of code writes to
# the console, then try it for yourself:
# puts "\\".gsub("\\", "\\\\")

puts "\\".gsub("\\", "\\\\")
#=3D> nil

# Why is that so?

faq. escaping the escape in sub/gsub. search the archives.

maybe you want something like,=20

puts "\\".gsub("\\"){"\\\\"}
\#=3D> nil

ie, use block wc is a lot more handy.

kind regards -botp



Simon Krahnke

4/24/2008 12:29:00 PM

0

* martinus <martin.ankerl@gmail.com> (11:53) schrieb:

> Hello, I have a mini-ruby quiz. Guess what this line of code writes to
> the console, then try it for yourself:
>
> puts "\\".gsub("\\", "\\\\")
>
> Why is that so?

Well, it's an faq. In short: The backslash is special in strings *and*
in the replacement text. So for every literal backslash you need four
backslashes, which is quite unreadable. If you don't need \1 and Co you
better use the block form: gsub("\\") { "\\\\" }.

mfg, simon .... hth

Rick DeNatale

4/24/2008 1:16:00 PM

0

On Thu, Apr 24, 2008 at 8:35 AM, Simon Krahnke <overlord@gmx.li> wrote:
> * martinus <martin.ankerl@gmail.com> (11:53) schrieb:
>
>
>
> > Hello, I have a mini-ruby quiz. Guess what this line of code writes to
> > the console, then try it for yourself:
> >
> > puts "\\".gsub("\\", "\\\\")
> >
> > Why is that so?
>
> Well, it's an faq. In short: The backslash is special in strings *and*
> in the replacement text. So for every literal backslash you need four
> backslashes, which is quite unreadable. If you don't need \1 and Co you
> better use the block form: gsub("\\") { "\\\\" }.

Another thing which trips up newbies, and sometimes not so newbies, is
the difference between the contents of a sring, and the 'inspect'
presentation of a string, particularly when the string contains
escapes:

irb(main):001:0> puts "\\"
=> nil
irb(main):002:0> p "\\"
"\\"
=> nil

The point is that the literal string "\\" only contains one character.
The puts method shows you the contents of the string, while p (which
is practically equivalent to puts string.inspect produces a literal
representation.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

matt

4/25/2008 3:13:00 AM

0

martinus <martin.ankerl@gmail.com> wrote:

> Hello, I have a mini-ruby quiz. Guess what this line of code writes to
> the console, then try it for yourself:
>
> puts "\\".gsub("\\", "\\\\")

We were just up and down this road (and I gave a workaround):

<http://groups.google.com/group/comp.lang.ruby/msg/d370b68448...

m.


--
matt neuburg, phd = matt@tidbits.com, http://www.tidbits...
Leopard - http://www.takecontrolbooks.com/leopard-custom...
AppleScript - http://www.amazon.com/gp/product/...
Read TidBITS! It's free and smart. http://www.t...

Larry Hewitt

3/10/2011 6:18:00 PM

0

On 3/10/2011 11:46 AM, Yoorghis@Jurgis.net wrote:
> On Thu, 10 Mar 2011 10:06:44 -0600, "Eddie Haskell"<ikiki@ssaas.com>
> wrote:
>
>>
>>> Hm. So, before Reagan and Bush, the debt was lower, and by the time
>>> Clinton took office, it became higher.
>>
>> What is it about "as a fraction of GDP" do you not understand, door Matt?
>
>
> What is it about 80% of all debt since 1980 being caused by
> Republicans that you don't understand?
>
>

There were 5 major spending initiates this decade: Bush tax cut I, Bush
tax cut II, the 2004 medicare bill (that repugs had to,lie about the
cost to get passed), the Obama stimulus, and last year's tax package.

The first 3 were written entirely by repuglicons. The last has a little
bit more than 60% of its spending authored by repuglicons.

Repugs voted *for* the spending in greater numbers than dems for all but
the stimulus bill.

$3.3 TRILLION in debt.

Repug Bush lied hios way into two long term wares, and repugs in
congress jumped on board, voting unanimously for off budget allocations
for the wars.

To date more than $2 TRILLION in debt is directly related to these
unnecessary wars.

Related to the war effort, but budgeted separately has been a major
increase in defense spending, especially the revival or expansion of
weapons systems not needed or even wanted by the Pentagon ( remember the
f35 engine bill repugs tried to ram through but dems and tea partiers
killed last month, saving half a billion?)

Another trillion in borrowing.

Over 6 trillion in debt in 7 yaers, under repuglicon government.

Larry



>
>
>> =============================================================
>
> On Fri, 18 Sep 2009 16:32:34 -0700 (PDT), Kurtis T. Nicklas of
> 1293 Westbrook Ave, Elon, NC 27244-9372"
>
> <nickl...@bellsouth.net> wrote in message
>
>
>> I don't pay much attention to him these days, but I'd wager he's not
>> happy.
>
> You sure as shit paid attention when you got caught
> making all those late-night hang-up phone calls, didn't
> ya, Nickkkkers?
>
> CLICK ! ! !

wy

3/10/2011 6:31:00 PM

0

On Mar 10, 12:42 pm, "Eddie Haskell" <ik...@ssaas.com> wrote:
> "wy" <w...@myself.com> wrote in message
>
> news:e33e63e5-1892-454b-b434-5e82019b8ea2@t19g2000prd.googlegroups.com...
> On Mar 10, 11:10 am, "Eddie Haskell" <ik...@ssaas.com> wrote:
>
>
>
>
>
> > "Phlip" <phlip2...@gmail.com> wrote in message
>
> >news:77603c63-7650-4160-ba12-f88dc923ff21@l2g2000prg.googlegroups.com...
>
> > >> Hm. So, before Reagan and Bush, the debt was lower, and by the time
> > >> Clinton took office, it became higher.
>
> > > What comparative fractions were the DEFICITS?
>
> > > Oh, wait, Clinton balanced the budget. 0%. NVM...
>
> > Yeah, by being so disdained that he ushered in a republican congress that
> > put the kibosh on Hillarycare and the kind of insane spending we have seen
> > from a democrat president and congress.
>
> > To give Clinton credit is to either be lying or stupid. But then, that's
> > always the question with democrats. Lying or stupid. Lying or stupid.
>
> > Oh, and btw, the idea that you give a shit about deficits and debt is a
> > lie
> > as well.
> > Repugnants did nothing during Clinton's term to better the economy and
> > balance the budget.
>
> You're lying of course.
>
> > In fact, they voted against the very thing that
> > resulted in an improved economy, balanced budget and 23 million new
> > jobs being created - the Omnibus Budget Reconciliation Act of 1993,
> > a.k.a. the Deficit Reduction Act of 1993.  1993, got that?  Well
> > before the Repugnants took over Congress in 1995, after which they had
> > no choice but to go along with the Act which was already federal law
> > that they had voted against.  Ooh, that just had to be a kick in the
> > teeth for them.
>
> It raised the top marginal rate to 39.6%. Still below the average during
> even Reagan. Thanks to republicans, taxes and increased spending was kept in
> check and Reaganomics prevailed just like the great Ronaldus Maximus said it
> would.

Already you're getting too profoundly stoopid for your own good. Tell
you what, take a week off from your usenet posting and TV viewing,
since we know you don't have a job to take a week off from, and read
the entire bill yourself and then tell me what the Repugnants did that
wasn't already in place before they supposedly came to save the day:

http://www.gpo.gov/fdsys/pkg/BILLS-103hr2264eh/pdf/BILLS-103hr...



Joe Irvin

3/10/2011 6:32:00 PM

0



"wy" wrote in message
news:e33e63e5-1892-454b-b434-5e82019b8ea2@t19g2000prd.googlegroups.com...

On Mar 10, 11:10 am, "Eddie Haskell" <ik...@ssaas.com> wrote:
> "Phlip" <phlip2...@gmail.com> wrote in message
>
> news:77603c63-7650-4160-ba12-f88dc923ff21@l2g2000prg.googlegroups.com...
>
> >> Hm. So, before Reagan and Bush, the debt was lower, and by the time
> >> Clinton took office, it became higher.
>
> > What comparative fractions were the DEFICITS?
>
> > Oh, wait, Clinton balanced the budget. 0%. NVM...
>
> Yeah, by being so disdained that he ushered in a republican congress that
> put the kibosh on Hillarycare and the kind of insane spending we have seen
> from a democrat president and congress.
>
> To give Clinton credit is to either be lying or stupid. But then, that's
> always the question with democrats. Lying or stupid. Lying or stupid.
>
> Oh, and btw, the idea that you give a shit about deficits and debt is a
> lie
> as well.

Repugnants did nothing during Clinton's term to better the economy and
balance the budget. In fact, they voted against the very thing that
resulted in an improved economy, balanced budget and 23 million new
jobs being created - the Omnibus Budget Reconciliation Act of 1993,
a.k.a. the Deficit Reduction Act of 1993. 1993, got that? Well
before the Repugnants took over Congress in 1995, after which they had
no choice but to go along with the Act which was already federal law
that they had voted against. Ooh, that just had to be a kick in the
teeth for them.
*******************************************************************

"And 1993 -- the year of the giant Clinton tax hike -- was not the turning
point in the deficit wars, either. In fact, in 1995, two years after that
tax hike, the budget baseline submitted by the president's own Office of
Management and Budget and the nonpartisan Congressional Budget Office
predicted $200 billion deficits for as far as the eye could see. The figure
shows the Clinton deficit baseline. What changed this bleak outlook?

Newt Gingrich and company -- for all their faults -- have received virtually
no credit for balancing the budget. Yet today's surplus is, in part, a
byproduct of the GOP's single-minded crusade to end 30 years of red ink.
Arguably, Gingrich's finest hour as Speaker came in March 1995 when he
rallied the entire Republican House caucus behind the idea of eliminating
the deficit within seven years."
http://www.cato.org/pub_display.php?p...

Please read the whole article to see how the budget was balanced.

wy

3/10/2011 6:41:00 PM

0

On Mar 10, 1:31 pm, "Joe Irvin" <ji3...@sccoast.net> wrote:
> "wy"  wrote in message
>
> news:e33e63e5-1892-454b-b434-5e82019b8ea2@t19g2000prd.googlegroups.com...
>
> On Mar 10, 11:10 am, "Eddie Haskell" <ik...@ssaas.com> wrote:
>
>
>
>
>
> > "Phlip" <phlip2...@gmail.com> wrote in message
>
> >news:77603c63-7650-4160-ba12-f88dc923ff21@l2g2000prg.googlegroups.com...
>
> > >> Hm. So, before Reagan and Bush, the debt was lower, and by the time
> > >> Clinton took office, it became higher.
>
> > > What comparative fractions were the DEFICITS?
>
> > > Oh, wait, Clinton balanced the budget. 0%. NVM...
>
> > Yeah, by being so disdained that he ushered in a republican congress that
> > put the kibosh on Hillarycare and the kind of insane spending we have seen
> > from a democrat president and congress.
>
> > To give Clinton credit is to either be lying or stupid. But then, that's
> > always the question with democrats. Lying or stupid. Lying or stupid.
>
> > Oh, and btw, the idea that you give a shit about deficits and debt is a
> > lie
> > as well.
>
> Repugnants did nothing during Clinton's term to better the economy and
> balance the budget.  In fact, they voted against the very thing that
> resulted in an improved economy, balanced budget and 23 million new
> jobs being created - the Omnibus Budget Reconciliation Act of 1993,
> a.k.a. the Deficit Reduction Act of 1993.  1993, got that?  Well
> before the Repugnants took over Congress in 1995, after which they had
> no choice but to go along with the Act which was already federal law
> that they had voted against.  Ooh, that just had to be a kick in the
> teeth for them.
> *******************************************************************
>
> "And 1993 -- the year of the giant Clinton tax hike -- was not the turning
> point in the deficit wars, either. In fact, in 1995, two years after that
> tax hike, the budget baseline submitted by the president's own Office of
> Management and Budget and the nonpartisan Congressional Budget Office
> predicted $200 billion deficits for as far as the eye could see. The figure
> shows the Clinton deficit baseline. What changed this bleak outlook?
>
> Newt Gingrich and company -- for all their faults -- have received virtually
> no credit for balancing the budget. Yet today's surplus is, in part, a
> byproduct of the GOP's single-minded crusade to end 30 years of red ink.
> Arguably, Gingrich's finest hour as Speaker came in March 1995 when he
> rallied the entire Republican House caucus behind the idea of eliminating
> the deficit within seven years."http://www.cato.org/pub_display.php?p...
>
> Please read the whole article to see how the budget was balanced.

Cato is a libertarian think tank which is no different than
conservatism and, of course, they're going to skew it all in avor of
conservatives. The fact of the matter is that the groundwork had
already been laid by Clinton with the Omnibus bill and whatever
restructuring took place after it was passed was all done within the
framework of that bill. Here's the groundwork of it all:

http://www.gpo.gov/fdsys/pkg/BILLS-103hr2264eh/pdf/BILLS-103hr...

Don't worry, I don't expect you to read it, unless you had nothing to
do with your time for the next week or so, although you can an idea of
how extensive it was just from the chapter headings alone of the table
of contents.

Eddie Haskell

3/10/2011 6:44:00 PM

0


"wy" <wy_@myself.com> wrote in message
news:0066d612-dfb3-480f-a27d-2a020cd2bd7b@o21g2000prh.googlegroups.com...
On Mar 10, 12:42 pm, "Eddie Haskell" <ik...@ssaas.com> wrote:
> "wy" <w...@myself.com> wrote in message
>
> news:e33e63e5-1892-454b-b434-5e82019b8ea2@t19g2000prd.googlegroups.com...
> On Mar 10, 11:10 am, "Eddie Haskell" <ik...@ssaas.com> wrote:
>
>
>
>
>
> > "Phlip" <phlip2...@gmail.com> wrote in message
>
> >news:77603c63-7650-4160-ba12-f88dc923ff21@l2g2000prg.googlegroups.com...
>
> > >> Hm. So, before Reagan and Bush, the debt was lower, and by the time
> > >> Clinton took office, it became higher.
>
> > > What comparative fractions were the DEFICITS?
>
> > > Oh, wait, Clinton balanced the budget. 0%. NVM...
>
> > Yeah, by being so disdained that he ushered in a republican congress
> > that
> > put the kibosh on Hillarycare and the kind of insane spending we have
> > seen
> > from a democrat president and congress.
>
> > To give Clinton credit is to either be lying or stupid. But then, that's
> > always the question with democrats. Lying or stupid. Lying or stupid.
>
> > Oh, and btw, the idea that you give a shit about deficits and debt is a
> > lie
> > as well.
> > Repugnants did nothing during Clinton's term to better the economy and
> > balance the budget.
>
> You're lying of course.
>
> > In fact, they voted against the very thing that
> > resulted in an improved economy, balanced budget and 23 million new
> > jobs being created - the Omnibus Budget Reconciliation Act of 1993,
> > a.k.a. the Deficit Reduction Act of 1993. 1993, got that? Well
> > before the Repugnants took over Congress in 1995, after which they had
> > no choice but to go along with the Act which was already federal law
> > that they had voted against. Ooh, that just had to be a kick in the
> > teeth for them.
>
> It raised the top marginal rate to 39.6%. Still below the average during
> even Reagan. Thanks to republicans, taxes and increased spending was kept
> in
> check and Reaganomics prevailed just like the great Ronaldus Maximus said
> it
> would.

> Already you're getting too profoundly stoopid for your own good. Tell
> you what, take a week off from your usenet posting and TV viewing,
> since we know you don't have a job to take a week off from, and read
> the entire bill yourself and then tell me what the Repugnants did that
> wasn't already in place before they supposedly came to save the day:

Already did. Now, tell me why balancing the budget in the nineties was good,
while insane deficit spending now is also good.

wy: Uhhh.. Cuz democrats did it?

Heh heh..

Got 'em backed into a corner, Damn moron didn't thinka that..

When will they ever learn?

Heh heh..

-Eddie Haskell


wy

3/10/2011 6:52:00 PM

0

On Mar 10, 1:43 pm, "Eddie Haskell" <ik...@ssaas.com> wrote:
> "wy" <w...@myself.com> wrote in message
>
> news:0066d612-dfb3-480f-a27d-2a020cd2bd7b@o21g2000prh.googlegroups.com...
> On Mar 10, 12:42 pm, "Eddie Haskell" <ik...@ssaas.com> wrote:
>
>
>
>
>
> > "wy" <w...@myself.com> wrote in message
>
> >news:e33e63e5-1892-454b-b434-5e82019b8ea2@t19g2000prd.googlegroups.com...
> > On Mar 10, 11:10 am, "Eddie Haskell" <ik...@ssaas.com> wrote:
>
> > > "Phlip" <phlip2...@gmail.com> wrote in message
>
> > >news:77603c63-7650-4160-ba12-f88dc923ff21@l2g2000prg.googlegroups.com....
>
> > > >> Hm. So, before Reagan and Bush, the debt was lower, and by the time
> > > >> Clinton took office, it became higher.
>
> > > > What comparative fractions were the DEFICITS?
>
> > > > Oh, wait, Clinton balanced the budget. 0%. NVM...
>
> > > Yeah, by being so disdained that he ushered in a republican congress
> > > that
> > > put the kibosh on Hillarycare and the kind of insane spending we have
> > > seen
> > > from a democrat president and congress.
>
> > > To give Clinton credit is to either be lying or stupid. But then, that's
> > > always the question with democrats. Lying or stupid. Lying or stupid.
>
> > > Oh, and btw, the idea that you give a shit about deficits and debt is a
> > > lie
> > > as well.
> > > Repugnants did nothing during Clinton's term to better the economy and
> > > balance the budget.
>
> > You're lying of course.
>
> > > In fact, they voted against the very thing that
> > > resulted in an improved economy, balanced budget and 23 million new
> > > jobs being created - the Omnibus Budget Reconciliation Act of 1993,
> > > a.k.a. the Deficit Reduction Act of 1993. 1993, got that? Well
> > > before the Repugnants took over Congress in 1995, after which they had
> > > no choice but to go along with the Act which was already federal law
> > > that they had voted against. Ooh, that just had to be a kick in the
> > > teeth for them.
>
> > It raised the top marginal rate to 39.6%. Still below the average during
> > even Reagan. Thanks to republicans, taxes and increased spending was kept
> > in
> > check and Reaganomics prevailed just like the great Ronaldus Maximus said
> > it
> > would.
> > Already you're getting too profoundly stoopid for your own good.  Tell
> > you what, take a week off from your usenet posting and TV viewing,
> > since we know you don't have a job to take a week off from, and read
> > the entire bill yourself and then tell me what the Repugnants did that
> > wasn't already in place before they supposedly came to save the day:
>
> Already did.

Then explain the salient points in a nutshell and what the Repugnants
did different from it.

> Now, tell me why balancing the budget in the nineties was good,
> while insane deficit spending now is also good.

It's always good to do so. Too bad Reagan didn't do it, neither did
Bush 1 nor 2, and Obama wouldn't have had the problem he's got now if
it weren't for Reagan and Bush 1 as well as Bush 2, who not only
reversed the balanced budgeting process but also exacerbated the
situation with his loony policies and lack of oversight that all
culminated in the crash of 2008. Got a better defense for Repugnants?