learn_ruby_ch2_pt2 Flashcards
Convert character code into a character
Convert character into a character code
irb(main):011:0> 65.chr
=> “A”
irb(main):014:0> “A”.ord
=> 65
Old 1.8 approach of ?A is gone
Match a word character
Match any character in brackets
Match any character not in brackets
\w
[…]
[^…]
Matches zero or more occurrences of the previous regexp
Matches one or more occurrences of the previous regexp
Matches zero or one occurrences of the previous regexp
*
+
?
matches one or more (+) word characters (\w), and places all the matches in an array (hamlet)
hamlet = “The slings and arrows of outrageous fortune”
hamlet.scan(/\w+/) # => [“The”, “slings”, “and”, “arrows”, “of”, “outrageous”, “fortune”]
Get the square root of a number.
irb(main):012:0> Math.sqrt(16)
=> 4.0