Skip to content

Instantly share code, notes, and snippets.

@mcbouslog
mcbouslog / Screencast #20
Created May 15, 2015 05:52
Screencast #20
#Screencast #20
class Person
attr_reader :age, :occupation, :mood
def initialize(age)
@age = age
if @age < 19
@occupation = "student"
@mcbouslog
mcbouslog / Screencast #19
Created May 15, 2015 05:40
Screencast #19
#Screencast #19
class Person
def initialize(age)
@age = age
if @age < 19
@occupation = "student"
@mood = "carefree"
else
@mcbouslog
mcbouslog / Screencast #18
Created May 15, 2015 05:14
Screencast #18
#Screencast #18
class Person
def start
@age = 18
@occupation = "student"
@mood = "carefree"
return "good luck!"
end
@mcbouslog
mcbouslog / Screencast #17
Created May 15, 2015 04:50
Screencast #17
#Screencast #17
class Calculator
def double(number)
number * 2
end
def add(number1, number2)
number1 + number2
@mcbouslog
mcbouslog / Screencast #16
Created May 14, 2015 05:45
Screencast #16
#Screencast #16
class Cook
def gather_ingredients
"ingredients"
end
def chop
gather_ingredients.reverse!
@mcbouslog
mcbouslog / Screencast #15
Created May 14, 2015 04:35
Screencast #15
#Screencast #15
class Dog
def speak
puts "Woof!"
end
def chew_on_bone
puts "Mmmmm...."
@mcbouslog
mcbouslog / i_people_and_their_emails
Created May 13, 2015 05:30
i_people_and_their_emails
i_people_and_their_emails
people = [
{
"first_name" => "Bob",
"last_name" => "Jones",
"hobbies" => ["basketball", "chess", "phone tag"]
},
{
"first_name" => "Molly",
@mcbouslog
mcbouslog / h_people_and_their_hobbies
Created May 13, 2015 05:02
h_people_and_their_hobbies
h_people_and_their_hobbies
people = [
{
"first_name" => "Bob",
"last_name" => "Jones",
"hobbies" => ["basketball", "chess", "phone tag"]
},
{
"first_name" => "Molly",
@mcbouslog
mcbouslog / g_flatten
Created May 13, 2015 04:42
g_flatten
g_flatten
array = [["a", "b", "z"], ["c", "d"], ["e", "f"], ["g", "h", "i", "j"]]
new_array = []
array.each do |global_array|
global_array.each do |letter|
new_array << letter
end
@mcbouslog
mcbouslog / f_fibonacci_numbers
Created May 12, 2015 18:21
f_fibonacci_numbers
f_fibonacci_numbers
puts "The first 100 Fibonacci numbers are:"
num_array = [0, 1]
98.times do |index|
num_array << (num_array[index + 1] + num_array[index])
end