Write a program that will print a two-column ASCII table for both lowercase and uppercase letters and
the digits 0-9.

alphabet = [('A'..'Z'),('a'..'z')].collect{|characters| characters.to_a}.flatten
puts "Character\tASCII Number"
alphabet.each do |letter|
puts "#{letter}\t\t#{letter.ord}"
end

Or...

irb(main):001:0> (Array('A'..'Z')|Array('a'..'z')|Array('0'..'9')).each do |letter|
irb(main):002:1* puts "#{letter}\t\t#{letter[0]}"
irb(main):003:1> end

Or...

irb(main):001:0> (Array('A'..'Z')|Array('a'..'z')|Array('0'..'9')).each { |letter| puts "#{letter}\t\t#{letter[0]}" }

In my Ruby (Ruby 1.9.3 under WindowsXP), it does not show the ord by indexing character, but you need to do:

(Array('A'..'Z')|Array('a'..'z')|Array('0'..'9')).each do |letter|
    puts "#{letter}\t\t#{letter.ord}"
end

I'm sorry for not giving vital information. My Ruby is version 1.8.7. Any Ruby version 1.9+ will be using ord instead of indexing. :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.