the_Bare
(the Bare)
19 July 2002 19:21
1
Hi:
My apologies if this is a ridiculously simple question…
Giiven the following code:
line = file.readline.strip
# line = '; some line'
if line[0].to_s == ';' # false! line[0] = 59, not ';'
# ...
end
My problem is, line[0] returns a fixnum, which doesn’t compare with the
’;’ string. So… how do perform this comparison?
Thanks,
Cameron
···
–
"Perhaps a lunatic was simply a minority of one"
George Orwell
line[0] == ?;
or
/^;/ =~ line
?;' is a Fixnum literal, represents ascii code of char
;'.
···
At Sat, 20 Jul 2002 04:21:08 +0900, the Bare wrote:
My problem is, line[0] returns a fixnum, which doesn’t compare with the
‘;’ string. So… how do perform this comparison?
line[0,1]
although i sometimes get errors with that, so
line[0…0]
seems to work best
line[0] just returns the bytecode. go figure.
~transami
···
On Fri, 2002-07-19 at 13:21, the Bare wrote:
Hi:
My apologies if this is a ridiculously simple question…
Giiven the following code:
line = file.readline.strip
# line = '; some line'
if line[0].to_s == ';' # false! line[0] = 59, not ';'
# ...
end
My problem is, line[0] returns a fixnum, which doesn’t compare with the
‘;’ string. So… how do perform this comparison?
Thanks,
Cameron
–
“Perhaps a lunatic was simply a minority of one”
George Orwell
–
~transami
(") dobee dobee do…
\v/
^ ^
HAL_9000
(HAL 9000)
19 July 2002 19:30
4
Or: line[0…0] will give you a string.
Hal
···
----- Original Message -----
From: “GOTO Kentaro” gotoken@notwork.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, July 19, 2002 2:28 PM
Subject: Re: Character Code
At Sat, 20 Jul 2002 04:21:08 +0900, > the Bare wrote:
My problem is, line[0] returns a fixnum, which doesn’t compare with the
‘;’ string. So… how do perform this comparison?
line[0] == ?;
or
/^;/ =~ line
?;' is a Fixnum literal, represents ascii code of char
;'.
Dossy
(Dossy)
19 July 2002 23:45
5
?x being a shortcut for Fixnum literal is cool, but what an
incredible opportunity for code obfuscation!
This is legitimate Ruby: “?;??;:?;”
irb(main):001:0> ?;??;:?;
59
Heh.
– Dossy
···
On 2002.07.20, GOTO Kentaro gotoken@notwork.org wrote:
?;' is a Fixnum literal, represents ascii code of char
;'.
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
Dossy
(Dossy)
19 July 2002 23:46
6
Working in the other direction from everyone’s suggestions, I
might try:
if line[0].chr == ';'
# ...
end
– Dossy
···
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
the_Bare
(the Bare)
20 July 2002 02:21
7
Dossy wrote:
Working in the other direction from everyone’s suggestions, I
might try:
if line[0].chr == ';'
# ...
end
– Dossy
This has got to be the friendliest programming newsgroup in existence.
Thanks for everyone’s responses!
Cameron
Dossy, that’s probably the best one --LNO, least number of objects.
···
On Fri, 2002-07-19 at 17:46, Dossy wrote:
if line[0].chr == ';'
# ...
end
– Dossy
~transami
(") dobee dobee do…
\v/
^ ^