Created
November 13, 2014 18:19
-
-
Save passalini/134a79d4df617f855fe5 to your computer and use it in GitHub Desktop.
Using gsub with strings and hash
This file contains 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 changing_ending_char(string) | |
ending_chars = { | |
'!' => :_dangerous, | |
'?' => :_question | |
} | |
string.gsub(/(?<char>[\?|\!])/, ending_chars) | |
end | |
changing_ending_char('asd') # => 'asd' | |
changing_ending_char('asd!') # => 'asd_dangerous' | |
changing_ending_char('asd?') # => 'asd_question' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment