This file contains hidden or 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
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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
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?" |
NewerOlder