Jim's
Tutorials

Fall 2018
course
site

Rails Week 2

In week two, I did a few more smaller random things like making a vending machine, I made a dice-rolling game that actually took some brain cells to think about (posted below) and then I moved on to loops and doing exercises in that which I'll post below. You can find everything in more detail on Github.

Additionally, I listened to a few ruby on rails podcasts including this SUPER interesting SE daily podcast which discusses HOW MRUBY INTERACTS WITH SHOPIFY which is interesting because that kind of relates to wordpress (ended up using woocommerce but shopify was an option) .. and it talks about an interesting "bug bounty" shopify put up for people to look at bugs in the mruby they used to build their program..l

and ALSO it talks about mruby with MICROCONTROLLERS which is super interesting and mentions arduino specifically because apparently mruby is one of the first high-level languages that is modular enough that it's not too big for a microcontroller to use... yeah I suppose C is typically used with microcontrollers but mruby opens up a new frontier for robotics and accessibility on that end. So if I get enthusiastic about Ruby and microcontrollers maybe I should check out Mruby.

Nil exploration

Studied nil documentation to understand it better and played around with it with IRB: Nil Documentation

irb(main):007:0> "leslie".index("e")
=> 1
irb(main):008:0> nil?
=> false
irb(main):009:0> "zebra".index("z")
=> 0
irb(main):010:0> "zebra".index("l")
=> nil
irb(main):011:0> nil?
=> false
irb(main):012:0> nil
=> nil
irb(main):013:0> !nil
=> true
irb(main):014:0> nil.to_h
=> {}
irb(main):015:0> nil.to_i
=> 0
irb(main):016:0> nil.to_f
=> 0.0
irb(main):017:0> nil.to_a
=> []
irb(main):018:0> nil.to_s
=> ""
irb(main):019:0>

Indexing with a vending machine

studied indexing and made like a vending machine that spits out the location of the string you're in search of:

stuff_in_vending= "yellow", "green","blue","violet"

puts "what do you want? "
input = gets.chomp
if stuff_in_vending.include?(input)
    puts stuff_in_vending.index(input)
else
    puts "oh sorry we don't have that"


end

Value comparisons with a snow-shoveling exercise

made something that does comparisons and spits out a number depending on where your input falls and it works.

puts "hi, input the amount of snow your received in cubic ft and I'll give you a quote"
input = gets.chomp
if input.to_f >= 0 && input.to_i <= 49
    puts "that will be 20 bucks plz"
elsif input.to_f >= 50 && input.to_i <= 149
    puts "that will be 50 bucks plz"
elsif input.to_f >=150 && input.to_i <= 299
    puts "that will be 100 bucks please thanks"
elsif input.to_f >=300
    puts "thats a ton of snow. cost ya 150"
end

rock-paper-scissors

I did something that required two parts- something declaring what the comp and player would do in a game of rock paper scissors, then a loop that defined what was printed given the value of each random dice roll.

puts "this is a game of rock paper scissors. type 'start'"
input = gets.chomp
if input == "start"
puts "player input your number! 1 for paper, 2 for scissors, 3 for rock"
player_roll = gets.chomp
computer_roll = rand(3)+1
end

while computer_roll == 1 && player_roll == 1
    puts "you both got rock"
if computer_roll == 1 && player_roll == 1
    puts "#{player_roll}: #{computer_roll} comp got rock, player got rock, tie!"
elsif computer_roll == 2 && player_roll == 2
    puts "#{player_roll}: #{computer_roll} comp got scissors, player got scissors, tie!"

...etc

While Loop Excercises

Below are some exercises I did to learn about sending my ruby code into a loop. played around with "break" and things that make infinite loops.

puts "entering the park, running to the lake"
lap_count = 0

while lap_count < 3 do
    lap_count += 1
    puts "thats lap #{lap_count} around the park"
end

puts "now through the rest of the park"

AND

puts "wahts your favorite number? we'll count up to it from 1"
fav_num_str = gets.chomp
fav_num = fav_num_str.to_i

AND

counter = 0
while counter < fav_num do
    counter += 1
    puts counter
end

AND

continue = true
while(continue) do
    puts "here we're in the loop, go again? (t/f)"
    check = gets.chomp
    if check =='f'
        puts "the end"

    end
end

AND

10.times do
    puts "hello friend"
end