Syntax string[0]=?t

Hi!

Is there any good idea how should a character represented in ruby? The
current one looks weird an is not intuitive, and more and more such
things are inserted into ruby (@@var as a class variable eg.) , so it
begins to look like a perl program (and one character change → another
program ) :-/

BTW is there any possibility to write blocks like we can write
for i in [1,2,5,2,6,1,6]
puts i
end

But that time the each iterator is called, if I’m right.
Can I use it with other procedures accepting a block?

Gergo

±[Kontra, Gergely @ Budapest University of Technology and Economics]-+

    Email: kgergely@mcl.hu,  kgergely@turul.eet.bme.hu          |

URL: turul.eet.bme.hu/~kgergely Mobile: (+36 20) 356 9656 |
±------“Olyan langesz vagyok, hogy poroltoval kellene jarnom!”-------+
.
Magyar php mirror es magyar php dokumentacio: http://hu.php.net

Hi!

Is there any good idea how should a character represented in ruby? The
current one looks weird an is not intuitive, and more and more such
things are inserted into ruby (@@var as a class variable eg.) , so it
begins to look like a perl program (and one character change → another
program ) :-/

Well, you know about “if str[0] == ?M”, obviously. What’s wrong with that?
OK, it’s not intuitive, but it’s easy to learn and harmless. I like it,
actually. Like so much else in Ruby, it economises typing without sacrificing
readability.

?c Ruby
‘c’ Most other languages

That’s a 33% saving in screen real estate for the reasonably common operation
of specifying a specific individual character.

BTW is there any possibility to write blocks like we can write
for i in [1,2,5,2,6,1,6]
puts i
end

But that time the each iterator is called, if I’m right.
Can I use it with other procedures accepting a block?

No, only each. I really like the “for a in x” syntax, but then when you make a
minor variation and have to use “each_with_index” instead of the implicit
“each”, the code looks inconsistent, so most of the time I use explicit “each”
now.

Gergo

Gavin

···

From: “Kontra, Gergely” kgergely@mlabdial.hit.bme.hu