Ten Things Every Java Programmer Should Know About Ruby

F

Florian Frank

David said:
On Mon, 31 Jan 2005, Aredridel wrote:
Indeed. And the realization that Ruby's interpolation goes beyond
variables, and that the "extra" symbols aren't extra, is one of the
traditional rites of passage :)


You can do that in Perl, too:

print "1 + 1 = @{[1 + 1]}\n"
1 + 1 = 2

But if one thinks, that Ruby is ugly... ;)
 
H

Hal Fulton

David said:
Hi --




Indeed. And the realization that Ruby's interpolation goes beyond
variables, and that the "extra" symbols aren't extra, is one of the
traditional rites of passage :)

Let's also bear in mind that when there is an @ or a $ starting a variable
name (not an expression), the brackets are optional:

"x: #@myvar"



Hal
 
D

David A. Black

Hi --

David said:
On Mon, 31 Jan 2005, Aredridel wrote:
Indeed. And the realization that Ruby's interpolation goes beyond
variables, and that the "extra" symbols aren't extra, is one of the
traditional rites of passage :)


You can do that in Perl, too:

print "1 + 1 = @{[1 + 1]}\n"
1 + 1 = 2

The usual initial criticism of "#{x}" is that the brackets are "extra"
-- but then when it turns out that that's all you need for arbitrary
amounts of code, they suddenly seem less "extra" than what you'd need
in Perl to do anything similar :)


David
 
S

Stig Sandbeck Mathisen

Navindra Umanee said:
Ruby seems to lose here. The syntax #{@myvar} is a rare case of
ugliness.

I've become very fond of using:

"x: %s" % @myvar

....or even

"x: %s, y: %d" % [@myvar,
@myothervar]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top