Skip to content

Instantly share code, notes, and snippets.

@huezoaa
huezoaa / hello_world.rb
Created January 13, 2015 21:48
hello_world
puts "hello world!"
@huezoaa
huezoaa / wyncode.rb
Last active August 29, 2015 14:13
wyncode.rb
# My favorite questions from the Wyncode Ruby Units
#
#UNIT: Ruby syntax.
puts "Ruby Syntax: Float Money"
puts <<FLOATMONEY
------------
| Question |
------------
Someone buys a product from your website for $33.50.
@huezoaa
huezoaa / game_on.rb
Created January 14, 2015 22:40
Game_on
puts <<WELCOME
Please complete the lyrics below by entering
the missing word/phrase. If you make a mistake,
the test will end.
Good luck. Try not to screw up.
>> Beta version(01.14.2015)
@huezoaa
huezoaa / add_two.rb
Last active August 29, 2015 14:13
Add_two
# Add 2 to the number.
def add_two(number)
if number.respond_to? :+
if number.respond_to? :push
number.push 2
elsif number.respond_to? :upcase
# Your entry is must be a String
number + "2"
else
number + 2
@huezoaa
huezoaa / mad_max.rb
Last active August 29, 2015 14:13
Mad_Max
def max(num1, num2)
num1 > num2 ? num1 : num2
end
def test # Assume all entries are numeric
p max(1,2) == 2 # (Fixnum, Fixnum)
p max(2,1) == 2 # (Fixnum, Fixnum)
p max(0.1, 0.2) == 0.2 # (Float, Float)
p max(0.2, 0.1) == 0.2 # (Float, Float)
p max(1,1.1) == 1.1 # (Fixnum, Float)
@huezoaa
huezoaa / countdown.rb
Last active August 29, 2015 14:13
Happy New Year Countdown
# Homework assignment. Ruby Methods 2.
# Question #1
def countdown(n=10)
(0..n).each { |count|
p (n-count) != 0 ? "#{n-count}" : "Happy New Year!"
# Because .each returns an array that can't be indexed,
# p will print each element as it gets created
# by the loop. But "print" waits unitl the array is complete to spit it out!
@huezoaa
huezoaa / fizzbuzz.rb
Last active August 29, 2015 14:13
FizzBuzz
# Method fizzbuzz will have a default num parameter of 15
# so if I call it by mistake without passing a value, it will return
# "fizzbuzz" and I will know where to look in my code.
def fizzbuzz(num=15)
# Check for the most intricate condition first!
if (num % 3 == 0) and (num % 5 == 0)
puts "FizzBuzz!!!!!!"
@huezoaa
huezoaa / max_refactor.rb
Created January 18, 2015 20:26
Max Refactor
def max(num1, num2, *num)
num1 > num2 ? num1 : num2
end
def test # Assume all entries are numeric
p max(1,9,3,5,99,23,115,32,922,3983,38374,28474,10937134) == 9
p max(1,2) == 2 # (Fixnum, Fixnum)
p max(2,1) == 2 # (Fixnum, Fixnum)
p max(0.1, 0.2) == 0.2 # (Float, Float)
p max(0.2, 0.1) == 0.2 # (Float, Float)
@huezoaa
huezoaa / game_mo_memory.rb
Created January 19, 2015 17:36
mo_memory
mo = [] #The computer's sequence of lights.
#Does not clear through execution
your_entry = [] #The player's sequence of lights. Clears on every loop
level = 0 #Counter that increases with every loop.
#used to display level and add new index to mo array.
while mo == your_entry # Will run until player makes a mistake
print "\033c" # This clears the screen!
@huezoaa
huezoaa / christmas_tree_class.rb
Last active August 29, 2015 14:13
Christmas Tree w/ Class
# Dislays the specified character in the shape of a
# Christmas tree.
# Wyncode bootcamp. Ruby Classes and OOP
# Arguments for Christmas tree:
# size = number of lines (Fixnum)
# character = string character to use (String)
class ChristmasTree
def initialize(size=3, character="X")