Created
July 2, 2014 08:45
-
-
Save oceansize/63cbcf4a420a43074d28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_ascii_of(val) | |
@numero = [] # => [] | |
val.each_byte do |x| # => "Hello!" | |
@numero << x # => [72], [72, 101], [72, 101, 108], [72, 101, 108, 108], [72, 101, 108, 108, 111], [72, 101, 108, 108, 111, 33] | |
end # => "Hello!" | |
return @numero # => [72, 101, 108, 108, 111, 33] | |
end | |
def convert | |
@numero.map! do |x| # => [72, 101, 108, 108, 111, 33] | |
if (97..122).include? x # => false, true, true, true, true, false | |
(x - 32).chr # => "E", "L", "L", "O" | |
else | |
x.chr # => "H", "!" | |
end # => "H", "E", "L", "L", "O", "!" | |
end # => ["H", "E", "L", "L", "O", "!"] | |
@numero.join # => "HELLO!" | |
end | |
def uppercasing(string) | |
find_ascii_of(string) # => [72, 101, 108, 108, 111, 33] | |
convert # => "HELLO!" | |
end | |
uppercasing('Hello!') # => "HELLO!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment