What is ?E in str.index(?E)...

A

askingagain

Dear all
I am learning Ruby. "The Ruby Way" has following example.

irb(main):047:0> str = "Albert Einstein"
=> "Albert Einstein"
irb(main):048:0> str.index(?E)
=> 7
irb(main):049:0> str1 = "mathematics"
=> "mathematics"
irb(main):050:0> flag1 = str1.include? ?e
=> true
irb(main):051:0>

What is ?E

(Does ? above work like shell globbing?)

I tried the FAQ online but could not get anything..

TIA for any pointers/online help

-- thx atul
 
A

ara.t.howard

Dear all
I am learning Ruby. "The Ruby Way" has following example.

irb(main):047:0> str = "Albert Einstein"
=> "Albert Einstein"
irb(main):048:0> str.index(?E)
=> 7
irb(main):049:0> str1 = "mathematics"
=> "mathematics"
irb(main):050:0> flag1 = str1.include? ?e
=> true
irb(main):051:0>

What is ?E

(Does ? above work like shell globbing?)

I tried the FAQ online but could not get anything..

TIA for any pointers/online help

-- thx atul


cfp:~ > cat a.rb
p ?A
p 'A'[0]
p 65.chr



cfp:~ > ruby a.rb
65
65
"A"

a @ http://codeforpeople.com/
 
K

Kam-Hung Soh

askingagain said:
Dear all
I am learning Ruby. "The Ruby Way" has following example.

irb(main):047:0> str = "Albert Einstein"
=> "Albert Einstein"
irb(main):048:0> str.index(?E)
=> 7
irb(main):049:0> str1 = "mathematics"
=> "mathematics"
irb(main):050:0> flag1 = str1.include? ?e
=> true
irb(main):051:0>

What is ?E

(Does ? above work like shell globbing?)

I tried the FAQ online but could not get anything..

TIA for any pointers/online help

-- thx atul

See: http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html

"You can also get the integer value corresponding to an ASCII character
or escape sequence by preceding it with a question mark."
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top