Skip to content

Instantly share code, notes, and snippets.

@huezoaa
huezoaa / wyncode.rb
Last active Aug 29, 2015
wyncode.rb
View 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.
View game_on.rb
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)
View mad_max.rb
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)
View add_two.rb
# 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 / countdown.rb
Last active Aug 29, 2015
Happy New Year Countdown
View countdown.rb
# 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!
View fizzbuzz.rb
# 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!!!!!!"
View max_refactor.rb
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)
View game_mo_memory.rb
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 Aug 29, 2015
Christmas Tree w/ Class
View christmas_tree_class.rb
# 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")