Created
December 11, 2013 13:11
-
-
Save AlexVPopov/7910165 to your computer and use it in GitHub Desktop.
Ruby cheatsheet
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
__foo__ = "This foo sentence contains many foo instances, for example: foo, foo, foo." | |
* Match a single symbol: `foo.match /./ # => #<MatchData "T">` | |
* Match the first-found word character symbol: `foo.match /\w/ => #<MatchData "T">` | |
* Extract all symbols of a string: `foo.scan /./ # => ["T", | |
"h", | |
"i", | |
"s", | |
" ", | |
"f", | |
"o", | |
"o", | |
" ", | |
"s", | |
"e", | |
"n", | |
"t", | |
"e", | |
"n", | |
"c", | |
"e", | |
" ", | |
"c", | |
"o", | |
"n", | |
"t", | |
"a", | |
"i", | |
"n", | |
"s", | |
" ", | |
"m", | |
"a", | |
"n", | |
"y", | |
" ", | |
"f", | |
"o", | |
"o", | |
" ", | |
"i", | |
"n", | |
"s", | |
"t", | |
"a", | |
"n", | |
"c", | |
"e", | |
"s", | |
",", | |
" ", | |
"f", | |
"o", | |
"r", | |
" ", | |
"e", | |
"x", | |
"a", | |
"m", | |
"p", | |
"l", | |
"e", | |
":", | |
" ", | |
"f", | |
"o", | |
"o", | |
",", | |
" ", | |
"f", | |
"o", | |
"o", | |
",", | |
" ", | |
"f", | |
"o", | |
"o", | |
"."] ` | |
* Extract n-member group of symbols - e.g. groups of 3 symbols `foo.scan /.../ # => ["Thi", | |
"s f", | |
"oo ", | |
"sen", | |
"ten", | |
"ce ", | |
"con", | |
"tai", | |
"ns ", | |
"man", | |
"y f", | |
"oo ", | |
"ins", | |
"tan", | |
"ces", | |
", f", | |
"or ", | |
"exa", | |
"mpl", | |
"e: ", | |
"foo", | |
", f", | |
"oo,", | |
" fo"]` | |
* Match the whole string: `foo.match /.+/ # => #<MatchData "This foo sentence contains many foo instances, for example: foo, foo, foo.">` | |
`foo.match /.*/ # => #<MatchData "This foo sentence contains many foo instances, for example: foo, foo, foo.">` | |
> Written with [StackEdit](https://stackedit.io/). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment