learn_ruby_ch2_pt2 Flashcards

1
Q

Convert character code into a character

Convert character into a character code

A

irb(main):011:0> 65.chr
=> “A”
irb(main):014:0> “A”.ord
=> 65

Old 1.8 approach of ?A is gone

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Match a word character

Match any character in brackets

Match any character not in brackets

A

\w

[…]

[^…]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

*

+

?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

matches one or more (+) word characters (\w), and places all the matches in an array (hamlet)

A

hamlet = “The slings and arrows of outrageous fortune”

hamlet.scan(/\w+/) # => [“The”, “slings”, “and”, “arrows”, “of”, “outrageous”, “fortune”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Get the square root of a number.

A

irb(main):012:0> Math.sqrt(16)

=> 4.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly