Skip to content

Instantly share code, notes, and snippets.

@fenixbrassi
Created December 16, 2013 03:27
Show Gist options
  • Save fenixbrassi/7981877 to your computer and use it in GitHub Desktop.
Save fenixbrassi/7981877 to your computer and use it in GitHub Desktop.
The longes string
def give_the_longest(array_strings)
longest_string = ""
array_strings.split(',').each do |x|
if x.length > longest_string.length
longest_string = x
end
end
longest_string
end
puts "Give me 5 strings separete by commas"
words = gets
puts "\n"
puts "The longest string is: #{give_the_longest
(words)}"
-------------------
Result console is:
C:\Training>ruby longest_string.rb
Give me 5 strings separete by commas
asfasdf,asfas,fa,sf,as,df,as,fa,s,fa,sdf,a,sf,as,dff,a
sfafdasfasfasfasfasdfasdfa
sfasdf2
The longest string is:
asfafdasfasfasfasfasdfasdfas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment