This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "hello world!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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!!!!!!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
class ConfPanel < ActiveRecord::Base | |
validates :code, presence: true | |
validates :name, presence: true | |
def self.import_from_csv(csv_file) | |
ConfPanel.transaction do | |
ConfPanel.destroy_all | |
# Parse CSV content |
OlderNewer