News
you open up an I/O stream with dir : IO.popen File Directory Ruby     |     you don't need to use $_ with gets – you can assign the text it reads to any variable: temperature = gets : chomp Development Ruby     |     you don't even have to use single or double quotes to create a string : String Quotation String Ruby     |     you can use the length method on hashes just as you can on arrays. : Hash Length Hash Ruby     |     you can store numbers in hashes : Hash Creation Hash Ruby     |    

dev-code.info

Web Developers

Menu
  • HOME
  • php
  • Perl
  • Ruby
  • JavaScript
  • About Copyright

you open up an I/O stream with dir : IO.popen File Directory Ruby

January 4, 2020

# 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"]

 

Posts navigation

1 2 … 1,572 Next

Recent Posts

  • you open up an I/O stream with dir : IO.popen File Directory Ruby
  • you don't need to use $_ with gets – you can assign the text it reads to any variable: temperature = gets : chomp Development Ruby
  • you don't even have to use single or double quotes to create a string : String Quotation String Ruby
  • you can use the length method on hashes just as you can on arrays. : Hash Length Hash Ruby
  • you can store numbers in hashes : Hash Creation Hash Ruby

Recent Comments

    Categories

    • JavaScript
    • Perl
    • php
    • Ruby
    • ubuntu linux
    dev-code.info | Proudly Powered by WordPress.
    Theme by Grace Themes

    sponsored