[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6068] '?' questions

From: "Guy N. Hurst" <gnhurst@...>
Date: 2000-11-05 12:00:11 UTC
List: ruby-talk #6068
I have been investigating the string capabilities in depth,
and came across some issues with ascii conversions.

In other languages, chr() and ord() are functions that
convert them, as in:
chr(65) -> "A"
ord("A") -> 65

In Ruby, we use:
65.chr -> "A"
?A -> 65

Well, I was going to try to define a method String#ord, and
discovered that the '?' operator is purely a lexical thing
that looks at the character after it, so needless to say,
I had problems applying it to a string object.

Two issues follow from this.

1)
Is there some alternative to the following:

def ord
  ?(self[0].to_s)
end

obviously this doesn't work.  Am I missing some other method?


2)
In IRB, I get some funny output with '?':


irb(main):016:0> ?A
65			# ok...
irb(main):017:0> ?\\
92
irb(main):018:0> ?\1
1
irb(main):019:0> ?\6
6
irb(main):020:0> ?\7
7
irb(main):021:0> ?\8
56			# first surprise
irb(main):022:0> ?\9
57
irb(main):023:0> ?\10
8			# second surprise, but makes sense
irb(main):024:0> ?\11
9
irb(main):025:0> ?\80
SyntaxError: compile error	
(irb):25: parse error
(irb):25:in `irb_binding'
irb(main):026:0> 
irb(main):027:0> ?\70
56			# same as ?\8


I suppose it is expecting octal values...right?
Any explanation for the surprises?

Thanks,

Guy N. Hurst
-- 
HurstLinks Web Development    http://www.hurstlinks.com/
Norfolk, VA - (757)623-9688
PHP/MySQL - Ruby/Perl - HTML/Javascript

In This Thread

Prev Next