[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Accentuated function names

Jean-baptiste Hétier

12/15/2008 9:21:00 AM

Hello,

I've started a new project in Ruby. For once, my sourcecode is not in
English, but in French, and I'd like to know if its possible to have
accentuated letters for function names in the sourcecode.

I have encoded my file in UTF-8 and it is parsed fine on Linux, but on
Windows, I get warnings and errors:
main.rb:16: Invalid char `\303' in expression

Also, the accents do not display properly in the error messages:
main.rb:34: syntax error, unexpected tFID, expecting '\n' or ';'
def apprâ??®cie?(voisin)
(instead of "apprécie?(voisin)")

Is there a way to specify sourcefile encoding? I could drop the accents
in the source, but they make the code much more readable!

Thanks.
--
Posted via http://www.ruby-....

6 Answers

Jean-baptiste Hétier

12/15/2008 10:56:00 AM

0

Robert Klemme wrote:
> IMHO it is generally a good idea to stick with 7 bit ASCII in source
> code. Also, I would never use my mother tongue for source code,
> partly because keywords are English anyway (even though Matz is
> Japanese) and partly because English is the lingua franca of IT. I
> know, this is not what you wanted to hear. :-)

Thanks for your answer!

Yeah, I'll probably switch back to English... but I'm still interested
in a solution. In Python you can define the file encoding in some kind
of file header:
#!/usr/bin/python
# -*- coding: <encoding name> -*-
I'm sure there's a way to do that in Ruby as well, but couldn't find it
anywhere :(
--
Posted via http://www.ruby-....

Jean-baptiste Hétier

12/15/2008 11:08:00 AM

0

Jean-baptiste Hétier wrote:
> I'm sure there's a way to do that in Ruby as well, but couldn't find it
> anywhere :(

Mmmh, I just found the following link:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...

It probably hasn't been implemented yet... Oh well...

--
Posted via http://www.ruby-....

F. Senault

12/15/2008 11:19:00 AM

0

Le 15 décembre 2008 à 12:08, Jean-baptiste Hétier a écrit :

> Jean-baptiste Hétier wrote:
>> I'm sure there's a way to do that in Ruby as well, but couldn't find it
>> anywhere :(
>
> Mmmh, I just found the following link:
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-...
>
> It probably hasn't been implemented yet... Oh well...

It has. In Ruby 1.9.

Fred
--
Toute ressemblance avec un message écrit par un être au moins aussi
intelligent qu'un singe tapant sur une machine à écrire pour reproduire
du Shakespeare serait purement fortuite; prière de prévenir en cas de
miracle. (Jokeuse, sur #lacave)

Jean-baptiste Hétier

12/15/2008 12:37:00 PM

0

F. Senault wrote:
> It has. In Ruby 1.9.

Excellent !
Thanks Fred.
--
Posted via http://www.ruby-....

pjb

12/15/2008 1:32:00 PM

0

Jean-baptiste Hétier <djib.nospam@think-underground.com> writes:

> Robert Klemme wrote:
>> IMHO it is generally a good idea to stick with 7 bit ASCII in source
>> code. Also, I would never use my mother tongue for source code,
>> partly because keywords are English anyway (even though Matz is
>> Japanese) and partly because English is the lingua franca of IT. I
>> know, this is not what you wanted to hear. :-)
>
> Thanks for your answer!
>
> Yeah, I'll probably switch back to English... but I'm still interested
> in a solution.

Ne te laisse pas dominer par le langage ! La solution c'est de passer
de MatzacredLisp à Common Lisp (par exemple: http://clis...) :

C/USER[4]> (defun décrémenter (x) (1- x))
DÉCRÉMENTER
C/USER[5]> (décrémenter 42)
41
C/USER[6]>


> In Python you can define the file encoding in some kind
> of file header:
> #!/usr/bin/python
> # -*- coding: <encoding name> -*-
> I'm sure there's a way to do that in Ruby as well, but couldn't find it
> anywhere :(

AFAIK, python doesn't use that line.
It's emacs that uses to store buffer local variables.

All my scripts start with:

#!/usr/bin/clisp -ansi -q
;; -*- mode:lisp; coding:utf-8; -*-


--
__Pascal Bourguignon__

Ollivier Robert

12/15/2008 1:48:00 PM

0

In article <91991a7c6c47ae31b3de62a62d015d4c@ruby-forum.com>,
Jean-baptiste Hétier <djib.nospam@think-underground.com> wrote:
>Yeah, I'll probably switch back to English... but I'm still interested
>in a solution. In Python you can define the file encoding in some kind
>of file header:
> #!/usr/bin/python
> # -*- coding: <encoding name> -*-

As it was already said, 1.9 does support the Encoding string but for 1.8, you may want to try adding "-Ku" to your Ruby invocation.

395 [14:46] roberto@roberto-al:/tmp> ruby -Ku foo.rb
Bonjour
396 [14:46] roberto@roberto-al:/tmp> cat foo.rb
#! /opt/local/bin/ruby -Ku
#
def été(foo)
puts(foo)
end

été("Bonjour")

With foo.rb written with utf-8 encoding.
--
Ollivier ROBERT -=- EEC/RIF/SEU -=-
Systems Engineering Unit