Permalink
Browse files

hard way updates

  • Loading branch information...
1 parent a17be95 commit 1bb85386a025a761d03f658e33373de3434efd35 @jholton committed Jan 11, 2013
Showing with 169 additions and 0 deletions.
  1. +15 −0 ex10.rb
  2. +8 −0 ex11.rb
  3. +10 −0 ex12.rb
  4. +8 −0 ex13.rb
  5. +22 −0 ex14.rb
  6. +14 −0 ex15.rb
  7. +4 −0 ex15_sample.txt
  8. +33 −0 ex16.rb
  9. +26 −0 ex7.rb
  10. +12 −0 ex8.rb
  11. +14 −0 ex9.rb
  12. +3 −0 test.txt
View
@@ -0,0 +1,15 @@
+tabby_cat = "\tI'm tabbed in."
+persian_cat = "I'm split\non a line."
+backslash_cat = "I'm \\ a \\ cat."
+
+fat_cat = <<MY_HEREDOC
+I'll do a list:
+\t* Cat food
+\t* Fishies
+\t* Catnip\n\t* Grass
+MY_HEREDOC
+
+puts tabby_cat
+puts persian_cat
+puts backslash_cat
+puts fat_cat
View
@@ -0,0 +1,8 @@
+print "How old are you? "
+age = gets.chomp
+print "How tall are you? "
+height = gets.chomp
+print "How much do you weigh? "
+weight = gets.chomp
+
+puts "So, you're #{age} years old, #{height} tall and #{weight} heavy."
View
@@ -0,0 +1,10 @@
+require 'open-uri'
+
+open("http://www.ruby-lang.org/en") do |f|
+ f.each_line {|line| p line}
+ puts f.base_uri # <URI::HTTP:0x40e6ef2 URL:http://www.ruby-lang.org/en/>
+ puts f.content_type # text/html
+ puts f.charset # "iso-8859-1
+ puts f.content_encoding # []
+ puts f.last_modified # Thu Dec 05 02:45:02 UTC 2002
+end
View
@@ -0,0 +1,8 @@
+first, second, third = ARGV
+
+puts "The script is called: #{$0}"
+puts "Your first variable is: #{first}"
+puts "Your second variable is: #{second}"
+puts "Your third variable is: #{third}"
+
+
View
@@ -0,0 +1,22 @@
+user = ARGV.first
+prompt = '> '
+
+puts "Hi #{user}, I'm the #{$0} script."
+puts "I'd like to ask you a few questions."
+puts "Do you like me #{user}?"
+print prompt
+likes = STDIN.gets.chomp()
+
+puts "Where do you live #{user}?"
+print prompt
+lives = STDIN.gets.chomp()
+
+puts "What kind of computer do you have?"
+print prompt
+computer = STDIN.gets.chomp()
+
+puts <<MESSAGE
+Alright, so you said #{likes} about liking me.
+You live in #{lives}. Not sure where that is.
+And you have a #{computer} computer. Nice.
+MESSAGE
View
@@ -0,0 +1,14 @@
+filename = ARGV.first
+
+prompt = "> "
+txt = File.open filename
+puts "Here's your file: #{filename}"
+puts txt.read
+
+puts "I'll also ask you to type it again."
+print prompt
+file_again = STDIN.gets.chomp
+
+txt_again = File.open(file_again)
+
+puts txt_again.read
View
@@ -0,0 +1,4 @@
+This is stuff I typed into a file.
+It is really cool stuff.
+Lots and lots of fun to have in here.
+
View
@@ -0,0 +1,33 @@
+filename = ARGV.first
+script = $0
+
+puts "We're going to erase #{filename}."
+puts "If you don't want that, hit CTRL-C (^C)."
+puts "If you do want that, hit RETURN."
+
+print "? "
+STDIN.gets
+
+puts "Opening the file..."
+target = File.open(filename, 'w')
+
+puts "Truncating the file. Goodbye!"
+target.truncate(target.size)
+
+puts "Now I'm going to ask you for three lines."
+
+print "line 1: "; line1 = STDIN.gets.chomp
+print "line 2: "; line2 = STDIN.gets.chomp
+print "line 3: "; line3 = STDIN.gets.chomp
+
+puts "I'm going to write these to the file."
+
+target.write(line1)
+target.write("\n")
+target.write(line2)
+target.write("\n")
+target.write(line3)
+target.write("\n")
+
+puts "And finally we close it."
+target.close()
View
@@ -0,0 +1,26 @@
+puts "Mary had a little lamb."
+puts "It's fleece was white as %s." % 'snow'
+puts "And everywher that Mary went."
+puts "." * 10 # what'd that do?
+
+end1 = "C"
+end2 = "h"
+end3 = "e"
+end4 = "e"
+end5 = "s"
+end6 = "e"
+end7 = "B"
+end8 = "u"
+end9 = "r"
+end10 = "g"
+end11 = "e"
+end12 = "r"
+
+# notice how we are ausing print instead of uts here. change it to puts
+# and see what happens.
+print end1 + end2 + end3 + end4 + end5 + end6
+print end7 + end8 + end9 + end10 + end11 + end12
+
+# this just is polite use of the terminal, try removing it
+puts
+
View
@@ -0,0 +1,12 @@
+formatter = "%s %s %s %s"
+
+puts formatter % [1, 2, 3, 4]
+puts formatter % ["one", "two", "three", "four"]
+puts formatter % [true, false, false, true]
+puts formatter % [formatter, formatter, formatter, formatter]
+puts formatter % [
+ "I had this thing.",
+ "That you could type up right.",
+ "But it didn't sing.",
+ "So I said goodnight."
+]
View
@@ -0,0 +1,14 @@
+# Here's some new strange stuff, remember type it exactly.
+
+days = "Mon Tue Wed Thu Fri Sat Sun"
+months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
+
+puts "Here are the days: ", days
+puts "Here are teh months: ", months
+
+puts <<-PARAGRAPH
+There's something going on here.
+ With the PARAGRAGH thing
+We'll be able to type as much as we like.
+ Even 4 lines if we want, or 5, or 6.
+ PARAGRAPH
View
@@ -0,0 +1,3 @@
+this is the first line
+and a second
+lastly, athird

0 comments on commit 1bb8538

Please sign in to comment.