Skip to main content
Mod Removes Wiki by Doorknob
Add ~/regexp/, explain Ruby 1.8 versus 1.9
Source Link
kernigh
  • 2.9k
  • 24
  • 25

$_ is last read line. Also

  • print - if no argument given print content of $_
  • ~/regexp/ - short for $_=~/regexp/

In Ruby 1.8, you have four methods in Kernel that operate on $_:

  • chop
  • chomp
  • sub
  • gsub
  • print - if no argument given print content of $_

In Ruby 1.9, these four methods exist only if your script uses -n or -p.

If you want to print some variable often then use trace_var(:var_name){|a|p a}

$_ is last read line. Also you have methods in Kernel that operate on $_:

  • chop
  • chomp
  • sub
  • gsub
  • print - if no argument given print content of $_

If you want to print some variable often then use trace_var(:var_name){|a|p a}

$_ is last read line.

  • print - if no argument given print content of $_
  • ~/regexp/ - short for $_=~/regexp/

In Ruby 1.8, you have four methods in Kernel that operate on $_:

  • chop
  • chomp
  • sub
  • gsub

In Ruby 1.9, these four methods exist only if your script uses -n or -p.

If you want to print some variable often then use trace_var(:var_name){|a|p a}

Source Link
Hauleth
  • 1.6k
  • 15
  • 20

$_ is last read line. Also you have methods in Kernel that operate on $_:

  • chop
  • chomp
  • sub
  • gsub
  • print - if no argument given print content of $_

If you want to print some variable often then use trace_var(:var_name){|a|p a}