Skip to content

Instantly share code, notes, and snippets.

View HintikkaKimmo's full-sized avatar

Kimmo Hintikka HintikkaKimmo

View GitHub Profile
class Person
#have a first_name and last_name attribute with public accessors
#attr_accessor
attr_accessor :first_name, :last_name
#have a class attribute called `people` that holds an array of objects
@@people = []
#have an `initialize` method to initialize each instance
@HintikkaKimmo
HintikkaKimmo / module2_lesson2_formative.rb
Last active January 4, 2016 20:44
Lesson 2 solution
# Grab 23 random elements between 0 and 10000
arr = (1..10000).to_a.sample(23)
p arr
# This selects only elements that when divided by 3 have a remainder of 0
# using the % (modulus) operator
p arr.select { |element| element % 3 == 0 }
# Using `reject` method filter out anything less than 5000
# and use `sort` and `reverse` methods to sort in descending order
@HintikkaKimmo
HintikkaKimmo / module2_lesson1_formative.rb
Created January 4, 2016 15:49
Solution for Formative Assignment for Module #2, Lesson #1: Case Statement
some_var = "false"
another_var = "nil"
case
when some_var == "pink elephant"
puts "Don't think about the pink elephant!"
when another_var.nil?
puts "Question mark in the method name?"
else
puts "I guess nothing matched... But why?"