Skip to content

Commit 2f64ff7

Browse files
Merge pull request #2 from polishExperiment/ruby_hway
Ruby_hway initial commit
2 parents d40133e + 16ac55b commit 2f64ff7

File tree

44 files changed

+1342
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1342
-0
lines changed

ruby_hway/ex1/test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
puts "Hello World!"
2+
puts "Hello Again"
3+
puts "I like typing this."
4+
puts "This is fun."
5+
puts "Yay! Printing."
6+
puts "I'd much rather you 'not'."
7+
puts 'I "said" do not touch this.'

ruby_hway/ex10/ex10.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tabby_cat = "\tI'm tabbed in."
2+
persian_cat = "I'm split\non a line."
3+
backlash_cat = "I'm \\ a \\ cat."
4+
5+
fat_cat = """
6+
I'll do a list:
7+
\t* Cat food
8+
\t* Fishies
9+
\t* Catnip\n\t* Grass
10+
"""
11+
12+
puts tabby_cat
13+
puts persian_cat
14+
puts backlash_cat
15+
puts fat_cat

ruby_hway/ex11/ex11.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
print "How old are you? "
2+
age = gets.chomp
3+
print "How tall are you? "
4+
height = gets.chomp
5+
print "How much do you weigh? "
6+
weight = gets.chomp
7+
8+
puts "So, you're #{age} old, #{height} tall and #{weight} heavy."

ruby_hway/ex12/ex12.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
print "Give me a number: "
2+
number = gets.chomp.to_f
3+
4+
bigger = number * 100
5+
puts "A bigger number is #{bigger}."
6+
7+
print "Give me another number: "
8+
another = gets.chomp
9+
number = another.to_f
10+
11+
smaller = number / 100
12+
puts "A smaller number is #{smaller}."

ruby_hway/ex13/ex13.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
first, second, third = ARGV
2+
3+
puts "Your first variable is: #{first}"
4+
puts "Your second variable is: #{second}"
5+
puts "Your third variable is: #{third}"
6+

ruby_hway/ex14/ex14.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
user_name = ARGV.first # gets the first argument
2+
prompt = '> '
3+
4+
puts "Hi #{user_name}."
5+
puts "I'd like to ask you a few questions."
6+
puts "Do you like me #{user_name}? "
7+
puts prompt
8+
likes = $stdin.gets.chomp
9+
10+
puts "Where do you live #{user_name}? "
11+
puts prompt
12+
lives = $stdin.gets.chomp
13+
14+
# a comma for puts is like using it twice
15+
puts "What kind of computer do you have? ", prompt
16+
computer = $stdin.gets.chomp
17+
18+
puts """
19+
Alright, so you said #{likes} about liking me.
20+
You live in #{lives}. Not sure where that is.
21+
And you have a #{computer} computer. Nice.
22+
"""

ruby_hway/ex15/ex15.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
filename = ARGV.first
2+
3+
txt = open(filename)
4+
5+
puts "Here's your file #{filename}:"
6+
print txt.read
7+
8+
close(filename)
9+
10+
print "Type the filename again: "
11+
file_again = $stdin.gets.chomp
12+
13+
txt_again = open(file_again)
14+
15+
print txt_again.read
16+
17+
close(file_again)

ruby_hway/ex15/ex15_sample.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is stuff I typed into a file.
2+
It is really cool stuff.
3+
Lots and lots of fun to have in here.

ruby_hway/ex16/ex16.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
filename = ARGV.first
2+
3+
puts "We're going to erase #{filename}"
4+
puts "If you don't want that, hit CTRL-C (^C)."
5+
puts "If you do want that, hit RETURN."
6+
7+
$stdin.gets
8+
9+
puts "Opening the file..."
10+
target = open(filename, 'w')
11+
12+
puts "Truncating the file. Goodbye!"
13+
target.truncate(0)
14+
15+
puts "Now I'm going to ask you for three lines."
16+
17+
print "line 1: "
18+
line1 = $stdin.gets.chomp
19+
print "line 2: "
20+
line2 = $stdin.gets.chomp
21+
print "line 3: "
22+
line3 = $stdin.gets.chomp
23+
24+
puts "I'm going to write these to the file."
25+
26+
new_line = "\n"
27+
target.write(line1 + new_line + line2 + new_line + line3 + new_line)
28+
29+
puts "And finally, we close it."
30+
target.close

ruby_hway/ex16/ex16_drill2.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
file = open(ARGV.first)
2+
puts file.read
3+
file.close
4+

0 commit comments

Comments
 (0)