Skip to content

Commit

Permalink
added more answers to ex22.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelakey committed Dec 14, 2011
1 parent 0cd0818 commit 1f901d2
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ex12_1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby

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-885901"
puts f.content_encoding # []
puts f.last_modified # Thu Dec 05 02:45:02 UTC 2002
end
105 changes: 105 additions & 0 deletions ex22.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
puts
prints a line of text
followed by a new line

" "
double quote
make a string by surrounding something with quotes

,
comma
apparently this separates a string from something else such as a math operation

#
comment
anything after one of these will be ignored by ruby

+
add

/
divide

%
percent
gets the percent of something 10 % 100 is 10

< >
less than, greater than

<= >=
less than or equal to, greater than or equal to

=
equals
assign a variable to something

#{}
embed a variable in a string like this "this is a string and a #{variable}

%s
format string
embed a variable in a string like this "this is a string and a %s" % variable

' '
single quote
make a string by surrounding something with quotes

puts "." * 10 # put something 10 times

print
similar to puts, prints something, but doesn't end with a newline

[ ]
square brackets
used with format strings like % [my_eyes, my_hair]

,
comma
this separates arguments such as [1, 2, 3, 4]

\
escape character
allows you to use a special character as if it's not special, as its normal non special self
<<
multi-line string
allows you to for instance puts a long string
()
parentheses
you can pass arguments into functions within these parentheses like new_function(argument1, argument2)
ARGV
the argument variable
all caps because it's a constant
can't change it once it's assigned
the arguments you provide when you run your ruby script are assigned to this variable ARGV

STDIN
standard input

gets
reads the next line from the IO stream

chomp()
by default removes carriage return characters
removes the given record separator

ARGV.first
the first argument that was passed into the script when the script was run

File.open(filename)
returns the value of the block?
this opens a file and assigns it some special code

txt.read()
read whatever's in txt

$0
variable which is assigned the name of the script

CTRL-C
abort


0 comments on commit 1f901d2

Please sign in to comment.