Skip to content

Instantly share code, notes, and snippets.

@oceansize
Created July 2, 2014 08:45
Show Gist options
  • Save oceansize/63cbcf4a420a43074d28 to your computer and use it in GitHub Desktop.
Save oceansize/63cbcf4a420a43074d28 to your computer and use it in GitHub Desktop.
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