⌘T | go to file |
⌘⌃P | go to project |
⌘R | go to methods |
⌃G | go to line |
⌘KB | toggle side bar |
⌘⇧P | command prompt |
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
class Vehicle | |
def initialize(args) | |
@color = args[:color] | |
@wheels = args[:wheels] | |
@gas_mileage = [true,false] | |
end | |
def drive | |
@status = :driving | |
end | |
def brake |
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 mode(array) | |
hash = Hash.new(0) | |
array.each { |elem| hash[elem] += 1 } | |
hash.keep_if { |k, v| v == hash.values.max }.keys | |
end |
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
class Person | |
def initialize(name, age, incoming_race) | |
@name = name | |
@age = age | |
self.race = incoming_race | |
end | |
def nam | |
@name.split.map(&:capitalize).join(" ") | |
end |
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 fizzblam | |
arr = (1..1000).to_a.map { |elem| [("Fizz" if (elem % 5).zero?), ("Buzz" if (elem % 7).zero?), (elem unless ((elem % 5).zero?) || ((elem % 7).zero?))].compact.join } | |
end | |
#another way to do it using string interpolation | |
def fizzblam | |
arr = (1..1000).to_a.map { |elem| "#{'Fizz' if elem % 3 == 0}#{'Buzz' if elem % 5 == 0}#{elem unless elem % 3 == 0 || elem % 5 == 0}" | |
end | |
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 addition item | |
@list[item] ? @list[item] += 1 : @list[item] = 1 | |
@list | |
end |
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 reverse_words(str) | |
str.split.each { |word| word.reverse!}.join(' ') | |
end |
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 separate_comma(number) | |
number.to_s.reverse.gsub(/(\d{3})(?=\d)(?!\d*\.)/, '\1,').reverse | |
end |
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
# Determine whether a string contains a Social Security number. | |
def has_ssn?(string) | |
string.match(/\d{3}\-\d\d\-\d{4}/) | |
end | |
# Return the Social Security number from a string. | |
def grab_ssn(string) | |
string[/\d{3}\-\d\d\-\d{4}/] | |
end |
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
class Die | |
def initialize(sides) | |
raise ArgumentError.new("Need at least one side") unless sides >= 1 | |
@sides = sides | |
end | |
def sides | |
@sides | |
end |