[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

value of block parameter before evaluation

tjmkiely

5/27/2006 8:46:00 PM

I have a basic question about expressions as parameters to blocks.

If I pass and expression as the parameter to a block, is it possible to
get the string representation of the expression before evaluation.

For example, with the following block:

write = proc { |x| file.write("x:#{x})")}

If called like this:

write[request.domain]

I would like to have this printed:

request.domain: localhost

Thanks.

5 Answers

Robert Klemme

5/27/2006 11:07:00 PM

0

tjmkiely@gmail.com wrote:
> I have a basic question about expressions as parameters to blocks.
>
> If I pass and expression as the parameter to a block, is it possible to
> get the string representation of the expression before evaluation.
>
> For example, with the following block:
>
> write = proc { |x| file.write("x:#{x})")}
>
> If called like this:
>
> write[request.domain]
>
> I would like to have this printed:
>
> request.domain: localhost

What you want is not possible with normal means. The simplest solution
would be to hand over the expression as string but then you also need to
provide the binding. Something along the lines

write = lambda {|expr, bind| file.write "#{expr}:#{eval(expr,bind)}" }

More complex solutions involve parsing the source code.

Cheers

robert

Daniel Schierbeck

5/28/2006 8:43:00 AM

0

tjmkiely@gmail.com wrote:
> write = proc { |x| file.write("x:#{x})")}
>
> If called like this:
>
> write[request.domain]
>
> I would like to have this printed:
>
> request.domain: localhost

I'm not sure, but maybe something along the lines of this?

write = proc{|x| file.write("#{x}: #{eval(x)}")}
write.call("request.domain")


Daniel

Timothy Goddard

5/29/2006 9:26:00 AM

0

This isn't possible as there is no 'string representation' that the
Ruby interpreter is aware of. It could be any expression, and the text
wouldn't exist at all at runtime. The easiest way to do something like
this is to pass in a hash and repeat a block for each name, value pair.

tjmkiely

5/30/2006 3:29:00 PM

0

Thanks Daniel.
That's what I was looking for. I didn't know about "eval".
Tim

Kathlene S. Echeverria

2/28/2013 11:32:00 PM

0

Real name Robert. Robert is a 4' 6" pygmy nigger, probably wider than
he is tall. He is an extreme deadbeat having been found guilty of
trying to steal from Capital One and even had his cellphone
confiscated for non-payment. Also, his mutant wife dumped him several
years ago...

Robert W Westergom (59 years old)
(Ex-wife) Erika Westergom (previously at Borders in Chestnut Hill, PA)
2524 Ebright Rd
Wilmington, DE 19810
(302) 475-5496

He claims to live in Philly but has never posted from Philly. He
mainly posts from a Delaware Public Library or a Barnes & Noble in the
Wilmington, DE, area using free wifi. He also uses free Google Groups
on a borrowed laptop. In his entire life he has contributed
absolutely nothing to society. Lies frequently but after many
beatings has become another usenet zoo monkey. Liars, once they have
been exposed, frequently revert to behavior most similar to a zoo
monkey who sits in the cage throwing feces at passersby but saying
nothing of value. Note that when you reply to a Proven Liar you
encourage them to continue lying.

[][][][][][]


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

[Courtesy of Buster Norris]

On Sun, 16 Dec 2012 17:44:57 -0800 (PST), robw <noddy093@comcast.net>
wrote:>On Dec 16, 5:10?pm, Kim V Woodard <woodard...@mailspinner.com>
wrote:>> On Sun, 16 Sep 2012 17:47:26 -0700 (PDT), robw
<noddy...@comcast.net>>> wrote:>> >Ritz filed for bankrupcy
protection.........when Bush was in office.>>
LIAR!!!!!!!!!!!!!!!!!!!!!!!!!>> George W. Bush - 43rd President of the
United States>> In office: January 20, 2001 January 20,
2009http://en.wikipedia.org/wiki/George_W._Bu... The company filed
for Chapter 11 bankruptcy protection on February 22,>> 2009.>> On June
22, 2012, Ritz Camera and Image filed for Chapter 11>> bankruptcy
protection for the second
time.http://en.wikipedia.org/wiki/Ritz_Came... wasn't the first
time they filed.LIAR!!!!!!!!!!!!!!!!!!!!!"The Denver Business Journal
reported that it's not Ritz's first experience with bankruptcy. The
photo retailer... filed for Chapter 11 in
2009........."http://www.bizjournals.com/pittsburgh/news/2012/06/25/ritz-camera-files-for-bankruptc...
filing WAS THE FIRST TIME, Robby The Midget...............
Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...