you open up an I/O stream with dir : IO.popen File Directory Ruby
# read the lines one by one, as with other forms of I/O streams, and close the stream ls = IO.popen("dir", "r") while line = ls.gets puts line end ls.close
you don't need to use $_ with gets – you can assign the text it reads to any variable: temperature = gets : chomp Development Ruby
print "Please enter the temperature: " temperature = gets $_ = temperature chomp temperature = $_ puts "The temperature is #{temperature}."
you don't even have to use single or double quotes to create a string : String Quotation String Ruby
# Ruby can add them if you use the %q (single quotes) or %Q (double quotes) syntax. puts %Q/Yes, that was Cary Grant./
you can use the length method on hashes just as you can on arrays. : Hash Length Hash Ruby
pizza = {"first_topping" => "pepperoni", "second_topping" => "sausage"} puts pizza.length
you can store numbers in hashes : Hash Creation Hash Ruby
receipts = {"day_one" => 5.03, "day_two" => 15_003.00} puts receipts["day_one"] puts receipts["day_two"]