Skip to content

Instantly share code, notes, and snippets.

View ashleygwilliams's full-sized avatar
>o_o<

ashley williams ashleygwilliams

>o_o<
View GitHub Profile
@ashleygwilliams
ashleygwilliams / gist:5682375
Last active December 17, 2015 22:29
practicing instance variables/methods and class variable/methods
#CLASS/INSTANCE METHODS AND VARIABLES PRACTICE:
#
#1. create a class called Project
class Project
#3. make the instance variables accessible by dot notation EXCEPT for date updated
attr_accessor :title, :description, :role, :date_created
#1. create a class variable called count
@@count = 0
@ashleygwilliams
ashleygwilliams / woodchuck.rb
Last active December 18, 2015 02:29
how much wood would a woodchuck chuck? a lesson in the difference between class and instance variables and methods.
class Woodchuck
attr_accessor :chuck_count
@@woodchuck_count = 0
def initialize
@chuck_count = 0
@@woodchuck_count += 1
end
i have [["a", "b", "c"],["a", "b", "z"],["d", "e", "f"],["d", "e", "p"]]
ok i need to buil {a=>??,d=>??}
THEN i need to build {a=>b, d=>e}
THEN i need to build {a=>{b=>??},d=>{e=>??}}
THEN i need to build {a=>{b=>[]]},d=>{e=>[]]}}
** maybe make [c,z] and [f,p]
THEN i need to build {a=>{b=>[c]]},d=>{e=>[f]]}}
@ashleygwilliams
ashleygwilliams / gist:5757248
Last active December 18, 2015 08:49
enumerable lab #2: decoder

##Objectives: Use String, Hash, Array, and Enumerable methods to decode a string and discover a secret message

INSPIRATION: http://www.youtube.com/watch?v=Wj1d85CLDOQ

##Skills: String.split, Array.each, Hash.each, Hash.sort_by, Range.to_a, Array.reverse, Array.push, Array.join, String.gsub, Array.index

##Instructions: Comments explain steps to manipulate string

@ashleygwilliams
ashleygwilliams / gist:5757253
Last active December 18, 2015 08:49
enumerable lab #3: pokemon

##Objectives:

Implement your own version of any?, all?, and none? to evaluate your pokemon team.

##Skills: any?, all?, none?, yield, blocks

##Instructions: Code contains a set of statements about a randomly generated pokemon team Implement and call your own versions of any?, all? and none? so that the statements are true.

@ashleygwilliams
ashleygwilliams / gist:5757256
Last active December 18, 2015 08:49
enumerable lab#1: green grocer

##Objectives: Create a checkout method to calculate the total cost of a cart of items and apply discounts and coupons as necessary.

Dr. Steve Bruhle, your green grocer, isn't ready, but you are!

##Skills: any?, all?, none?, each, map/collect

##Instructions: Code generates a random cart of items and a random set of coupons. Implement a method checkout to calculate total cost of a cart of items and apply discounts and coupons as necessary.

##create a hash that includes counts as a key for each item
myCart.each do |item|
myNewCart[item]||= {} #[{item}, {item}] => {{item}=>{}, {item}=>{}}
myNewCart[item][:count] ||= 0 #{{item}=>{:count=>0}, {item}=>{:count=>0}}
myNewCart[item][:count] += 1 #{{item}=>{:count=>+=1}, {item}=>{:count=>+=1}}
end
#ITEMS = [ {"AVOCADO" => {:price => 3.00, :clearance => true}},
# {"KALE" => {:price => 3.00,:clearance => false}},
# {"BLACK_BEANS" => {:price => 2.50,:clearance => false}},
# {"ALMONDS" => {:price => 9.00, :clearance => false}},
# {"TEMPEH" => {:price => 3.00,:clearance => true}},
# {"CHEESE" => {:price => 6.50,:clearance => false}},
# {"BEER" => {:price => 13.00, :clearance => false}},
# {"PEANUTBUTTER" => {:price => 3.00,:clearance => true}},
# {"BEETS" => {:price => 2.50,:clearance => false}}]
#
@ashleygwilliams
ashleygwilliams / gist:5762354
Created June 12, 2013 02:09
notes about arrays and hashes for alex
myArray = [1,2,3,4,5]
myArray[0] = 1
myArray[1] = 2
myArray.each do |arr|
puts arr
end
myHash = {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
@ashleygwilliams
ashleygwilliams / gist:5773822
Created June 13, 2013 13:51
notes from my talk about how to best approach the enumerable labs and complex projects in general
two things i want to accomplish in the next hour:
+ clarify the instructions for the enumerable labs
+ teach you guys about how to break problems down (in words)
+ in code (methods are your friend)
first things first:
+ how does everyone feel right now?
+ walls happen, perservere
+ when you don't understand the instructions, make your own and keep going because the solution is likely not going to be as different as if you had