[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

RCR: New interpreter switch

Martin DeMello

9/21/2003 1:30:00 PM

One place where perl's heavy use of implicit variables scores is in
quick one-liners from the command prompt. I think ruby would be more
appealing in that area if it had a switch that ran the following loop:

while gets
print $_.instance_eval {
...
}
end

This would generalise the existing technique of mixing a few String
methods like gsub and scan into Kernel and having them act implicitly on
$_.

martin
6 Answers

Eric Hodel

9/21/2003 2:20:00 PM

0

Martin DeMello (martindemello@yahoo.com) wrote:

> One place where perl''s heavy use of implicit variables scores is in
> quick one-liners from the command prompt. I think ruby would be more
> appealing in that area if it had a switch that ran the following loop:
>
> while gets
> print $_.instance_eval {
> ...
> }
> end
>
> This would generalise the existing technique of mixing a few String
> methods like gsub and scan into Kernel and having them act implicitly on
> $_.

Its already got that, use ruby -h. -n and -p do those things

Additionally:

$ ri Kernel#gets
----------------------------------------------------------- Kernel::gets
gets( aString=$/ ) -> aString or nil
------------------------------------------------------------------------
Returns (and assigns to $_) the next line from the list of files in
ARGV (or $*), or from standard input if no files are present on the
command line. Returns nil at end of file. The optional argument
specifies the record separator. The separator is included with the
contents of each record. A separator of nil reads the entire
contents, and a zero-length separator reads the input one paragraph
at a time, where paragraphs are divided by two consecutive
newlines. If multiple filenames are present in ARGV, gets(nil) will
read the contents one file at a time.
ARGV << "testfile"
print while gets
produces:
This is line one
This is line two
This is line three
And so on...


$ ri Kernel#scan
----------------------------------------------------------- Kernel::scan
scan( pattern ) -> anArray
scan( pattern ) {| | block } -> $_
------------------------------------------------------------------------
Equivalent to calling $_.scan. See String#scan on page 378.

$ ri Kernel#gsub
----------------------------------------------------------- Kernel::gsub
gsub( pattern, replacement ) -> aString
gsub( pattern ) {| | block } -> aString
------------------------------------------------------------------------
Equivalent to $_.gsub..., except that $_ receives the modified
result.
$_ = "quick brown fox"
gsub /[aeiou]/, ''*'' #=> "q**ck br*wn f*x"
$_ #=> "q**ck br*wn f*x"

--
Eric Hodel - drbrain@segment7.net - http://se...
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Martin DeMello

9/21/2003 2:51:00 PM

0

Eric Hodel <drbrain@segment7.net> wrote:
>
> Martin DeMello (martindemello@yahoo.com) wrote:
>> while gets
>> print $_.instance_eval {
>> ...
>> }
>> end

>> This would generalise the existing technique of mixing a few String
>> methods like gsub and scan into Kernel and having them act implicitly on
>> $_.
>
> Its already got that, use ruby -h. -n and -p do those things

No they don''t. For instance, calling the new flag -j (all the good names
were taken!)

ruby -n -e ''puts $_.split.join(" | ")''
ruby -p -e ''$_ = $_.split.join(" | ") + "\n"''
ruby -j -e ''split.join(" | ") + "\n"''

(and a nice convenience method to go along would be String#n, to add a
newline to the end of a string, so we could say ''split.join.n'')

> Additionally:
>
> $ ri Kernel#gets

[...]

Yes, that was the ''existing technique'' I referred to.

martin

Gavin Sinclair

9/21/2003 3:34:00 PM

0

On Sunday, September 21, 2003, 11:46:33 PM, Martin wrote:

> One place where perl''s heavy use of implicit variables scores is in
> quick one-liners from the command prompt. I think ruby would be more
> appealing in that area if it had a switch that ran the following loop:

> while gets
> print $_.instance_eval {
> ...
> }
> end

> This would generalise the existing technique of mixing a few String
> methods like gsub and scan into Kernel and having them act implicitly on
> $_.


An alternative would be to create a file that adds all the methods you
want to Kernel, and require that on the command line. Just a thought.

Gavin


Martin DeMello

9/21/2003 3:40:00 PM

0

Gavin Sinclair <gsinclair@soyabean.com.au> wrote:
> On Sunday, September 21, 2003, 11:46:33 PM, Martin wrote:
>
>> One place where perl''s heavy use of implicit variables scores is in
>> quick one-liners from the command prompt. I think ruby would be more
>> appealing in that area if it had a switch that ran the following loop:
>
>> while gets
>> print $_.instance_eval {
>> ...
>> }
>> end
>
>> This would generalise the existing technique of mixing a few String
>> methods like gsub and scan into Kernel and having them act implicitly on
>> $_.
>
>
> An alternative would be to create a file that adds all the methods you
> want to Kernel, and require that on the command line. Just a thought.

I thought of that - it doesn''t work because in several cases you''re
still left with having to assign the result to $_ or call print/puts
explicitly. A method that will work is to wrap a shell script around
ruby, that puts the loop and the instance_eval in for you. But it''d be
nicer to see it as a switch.

martin

Eddie Haskell

5/13/2011 3:58:00 PM

0


"SilentOtto" <silentotto@hotmail.com> wrote in message
news:257e5563-e6c5-4c06-b2ee-a2398383d9e8@w24g2000yqb.googlegroups.com...
On May 12, 11:28 am, "Eddie Haskell" <kim...@sawqo.com> wrote:
> "SilentOtto" <silento...@hotmail.com> wrote in message
>
> news:4e9a7733-a3cb-4c3d-9324-5314069df9aa@q14g2000prh.googlegroups.com...
> On May 11, 5:19 pm, "Eddie Haskell" <kim...@sawqo.com> wrote:
>
>
>
>
>
>
>
>
>
> > "Rightard Whitey" <rightar...@gmail.com> wrote in message
>
> >news:4dca046d$0$26686$9a6e19ea@unlimited.newshosting.com...
>
> > > It should be clear that most tax cuts are break-even propositions
> > > while
> > > temporary increases in food stamps, extending employment, and
> > > increased
> > > infrastructure spending have more of a multiplier effect on the tax
> > > dollar and are far more stimulative.
>
> > Yeah, fuck the fact that the "stimulus" was a total failure. To hell
> > with
> > reality.
>
> > > What have Republican governors like Rick Scott and Chris Christie been
> > > doing? They have been reducing the number of weeks an unemployed
> > > workers
> > > can draw unemployment while approving more tax cuts for corporations.
>
> > It's called trying to attract business so people will have jobs,
> > dumbfuck.
> > No it's not.
> > It's called socializing business costs, while profits stay private.
>
> No, it's called trying to attract business so people have jobs while your
> model is to suck it dry and languish in third-world Detroit poverty like
> third-world apes.

> Like I said, rightards, like you, are racist to the bone.

> African Americans didn't destroy Detroit, rightard.

That's because "African-Americans" only comprise about 5% of the black
population. The rest are niggers and that's who destroyed Detroit just like
everything they touch and everywhere on this planet they reside.

Heh heh..

Man, that one's gonna have smoke coming out of his ears..

Heh heh..

"Typical white person"

-Hussein

"Judge me by the people with whom I surround myself."

-Hussein

Hussein's associations:

Rev. Wright, whose church Hussein attended and supported financially for
over
20 years:

"Barack knows what it means living in a country and a culture that is
controlled by rich white people."

Rev. Lowery, hand picked by Hussein to deliver the inaugural benediction:

"Lord, in the memory of all the saints who from their labors rest, and in
the joy of a new beginning, we ask you to help us work for that day when
black will not be asked to get in back, when brown can stick around, when
yellow will be mellow, when the red man can get ahead, man; and when white
will embrace what is right."

Sonia Sotomayor, Hussein's pick for the SC:

"I would hope that a wise Latina woman with the richness of her experiences
would more often than not reach a better conclusion than a white male who
hasn't lived that life."

From Hussein's book:

"White man's greed runs a world in need."

Prof. Gates, anti-white racist who Obama says is a friend of his.

Obama advisor Van Jones:

"Only Suburban White Kids Shoot Up Schools"

"You've never seen a Columbine done by a black child"

"White polluters steered poison into minority communities"

"Coates, who said he was testifying before the commission as a whistle
blower and in violation of his Justice supervisor's instructions, said that
there is a "hostile atmosphere" in the civil rights division that did not
"reflect race neutral policies." He said the country's major civil rights
organizations are also biased against race-neutral enforcement."

http://tinyurl.c...

http://www.youtube.com/watch?v=1...

"In emotional and personal testimony, an ex-Justice official who quit over
the handling of a voter intimidation case against the New Black Panther
Party accused his former employer of instructing attorneys in the civil
rights division to ignore cases that involve black defendants and white
victims. "

http://tinyurl.c...

-Eddie Haskell



Buster Norris

5/15/2011 1:46:00 AM

0

The DemocRAT Hall Of Shame http://www.democrathallof... asks
"Why do you always LIE?"


From: SilentOtto <silentotto@hotmail.com>
NNTP-Posting-Host: 76.221.69.251

MICHAEL HAMMON (56) (Brenda - 60)
2338 Howe Rd
Burton, MI 48519
(810) 744-4114

http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=42.9950+-83.6246&sll=43.014266,-83.796694&sspn=0.007045,0.015492&ie=UTF8&ll=42.9995,-83.624861&spn=0,0.015492&t=h&z=16&layer=c&cbll=42.994927,-83.624276&panoid=ANrIvZ_pDBpdxUaf8fyyDQ&cbp=12,265....

http://tinyurl.c...

Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...