[Ruby]$: what does it mean

Use ruby ​​to capitalize the first letter of all words in a sentence

. There is no method in ruby ​​itself, you can use this:
str='this is a demo'
puts str.gsub(/\b\w/) { $&.upcase }



[Ruby] $: what does it mean?
ruby comes with a set of predefined variables

$: = default search path (array of paths)

Other Ruby special variables:
$! last error message
$@ error location
$_ gets last read string
$. interpreter last The number of lines read (line number)
$& The string that matches the regular expression last time
$~ The last match as a subexpression group
$n The nth subexpression that matches the most recently (same as $~[n])
$= case-sensitive flag
$/ input record separator
$\ output record separator
$0 Ruby script filename
$* command line arguments
$$ interpreter process ID
$? Exit status of the most recently executed child process

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326691837&siteId=291194637