Skip to content

Instantly share code, notes, and snippets.

@dharshan
Created April 28, 2017 10:16
Show Gist options
  • Save dharshan/e18b5e95710ae6ac5e78080f09c29908 to your computer and use it in GitHub Desktop.
Save dharshan/e18b5e95710ae6ac5e78080f09c29908 to your computer and use it in GitHub Desktop.
Reverse input string if input string length is less than 4
def string_rev_if_4(input)
return input.reverse if input.length < 4
input
end
string_rev_if_4("he") # "eh"
string_rev_if_4("hel") # "leh"
string_rev_if_4("hell") # "hell"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment