Skip to content

Instantly share code, notes, and snippets.

@npras
Created July 3, 2012 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npras/3038097 to your computer and use it in GitHub Desktop.
Save npras/3038097 to your computer and use it in GitHub Desktop.
Ruby Challenge 3: Capitalizing words within a string
# Challenge 3: http://www.therubygame.com/challenges/3/submissions
str = "The small brown & ginger fox JUMPED OVER the gate"
# output = "The Small Brown & Ginger Fox Jumped Over The Gate"
# Algorithm:
# 1. downcase #{str}
# 2. to_a
# 3. capitalize on each array elements
# 4. merge as str
def Capitalize(str)
str.split.each {|x| x.capitalize!}.join ' '
end
puts "ip: #{str}"
puts "op: #{Capitalize str}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment