Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / hello_world.rb
Created January 13, 2015 21:48
hello_world
puts "hello world!"