Browse files

Progress?

  • Loading branch information...
1 parent b85528b commit 908a72b9ec197ec03de5ce95cd1363013ecdcdbd @minghan committed Nov 16, 2011
Showing with 75 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 comments.txt
  3. 0 {ex01 → }/ex01.rb
  4. 0 {ex03 → }/ex03.rb
  5. 0 {ex04 → }/ex04.rb
  6. 0 {ex08 → }/ex08.rb
  7. +12 −0 ex10.rb
  8. +5 −0 ex11.rb
  9. +14 −0 ex12.rb
  10. +11 −0 ex13.rb
  11. +30 −0 ex14.rb
View
1 .gitignore
@@ -0,0 +1 @@
+*.swp
View
2 comments.txt
@@ -0,0 +1,2 @@
+for each not explained in ex12
+no clear explanation of chomp in ex14
View
0 ex01/ex01.rb → ex01.rb
File renamed without changes.
View
0 ex03/ex03.rb → ex03.rb
File renamed without changes.
View
0 ex04/ex04.rb → ex04.rb
File renamed without changes.
View
0 ex08/ex08.rb → ex08.rb
File renamed without changes.
View
12 ex10.rb
@@ -0,0 +1,12 @@
+puts <<SOMECRAP
+OK 1 2 3
+ yo
+ \t\t\nyo
+SOMECRAP
+
+
+# similar to python's triple quotes or php's echo <<<
+longstring = <<STUFF
+
+
+STUFF
View
5 ex11.rb
@@ -0,0 +1,5 @@
+print "how old are you?"
+
+age = gets.chomp() # sounds like perl
+
+puts "So, you are #{age} old" # nice thing abt rb's variable replacement
View
14 ex12.rb
@@ -0,0 +1,14 @@
+require 'open-uri'
+
+# require vs include: http://ruby.about.com/b/2008/10/23/a-quick-peek-at-ruby-include-vs-require.htm
+
+p "what?" # http://stackoverflow.com/questions/1758284/what-is-p-in-ruby
+ # obj.inspect
+
+open("http://www.ruby-lang.org/en") do |f|
+ # f.each_line{|line| p line} # prints everything
+
+ puts f.base_uri
+ puts f.content_type
+
+end
View
11 ex13.rb
@@ -0,0 +1,11 @@
+first, second, third = ARGV # ARGV[0],[1],[2]
+
+# note that the prog name is in $0 instead of argv
+# can compare $0 == __FILE__
+
+puts __FILE__
+
+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
30 ex14.rb
@@ -0,0 +1,30 @@
+user = ARGV.first # first elt in array
+ # http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-first
+
+# why chomp?
+# http://root2linux.com/2011/02/different-between-gets-and-gets-chomp-in-ruby/
+
+# chomp cuts the \n out
+
+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
+

0 comments on commit 908a72b

Please sign in to comment.