hi
when I type " puts ?a " irb doesn’t return ASCII code of a
character.why?
$ cat ruby.rb
puts ?a
$ multiruby ruby.rb
VERSION = 1.8.6-p420
CMD = ~/.multiruby/install/1.8.6-p420/bin/ruby ruby.rb
97
RESULT = pid 94689 exit 0
VERSION = 1.8.7-p352
CMD = ~/.multiruby/install/1.8.7-p352/bin/ruby ruby.rb
97
RESULT = pid 94690 exit 0
VERSION = 1.9.1-p431
CMD = ~/.multiruby/install/1.9.1-p431/bin/ruby ruby.rb
a
RESULT = pid 94691 exit 0
VERSION = 1.9.2-p290
CMD = ~/.multiruby/install/1.9.2-p290/bin/ruby ruby.rb
a
RESULT = pid 94692 exit 0
TOTAL RESULT = 0 failures out of 4
Passed: 1.8.6-p420, 1.8.7-p352, 1.9.1-p431, 1.9.2-p290
Failed:
Excuse me, I don’t understand what do you mean . please explain very
basic.
I am really beginner.
Hello Amir e.
Use this instead for 1.9.2:
‘a’.ord
97.chr
if you want to keep with the semantics of ? then you can always add
ordinal after the ? sigil which will convert it to a string:
?a.ord
~Stu
Things change.
puts ‘a’.ord
–output:–
97
$ cat ruby.rb
puts ‘a’.ord
$ multiruby ruby.rb
VERSION = 1.8.6-p420
CMD = ~/.multiruby/install/1.8.6-p420/bin/ruby ruby.rb
ruby.rb:1: undefined method `ord’ for “a”:String (NoMethodError)
RESULT = pid 94705 exit 1
VERSION = 1.8.7-p352
CMD = ~/.multiruby/install/1.8.7-p352/bin/ruby ruby.rb
ruby.rb:1: undefined method `ord’ for “a”:String (NoMethodError)
RESULT = pid 94706 exit 1
VERSION = 1.9.1-p431
CMD = ~/.multiruby/install/1.9.1-p431/bin/ruby ruby.rb
97
RESULT = pid 94707 exit 0
VERSION = 1.9.2-p290
CMD = ~/.multiruby/install/1.9.2-p290/bin/ruby ruby.rb
97
RESULT = pid 94708 exit 0
TOTAL RESULT = 2 failures out of 4
Passed: 1.9.1-p431, 1.9.2-p290
Failed: 1.8.6-p420, 1.8.7-p352