| ⌘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 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
| "blue" |
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
| def is_fibonacci?(i) | |
| x = 5 * i**2 + 4 | |
| m = x | |
| p = x | |
| loop do | |
| r = (m + p.to_f / m).to_f / 2 | |
| if m <= r | |
| break | |
| else |
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 Die | |
| def initialize(sides) | |
| raise ArgumentError.new("Need at least one side") unless sides >= 1 | |
| @sides = sides | |
| end | |
| def sides | |
| @sides | |
| end |
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
| # 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 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
| def separate_comma(number) | |
| number.to_s.reverse.gsub(/(\d{3})(?=\d)(?!\d*\.)/, '\1,').reverse | |
| end |
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
| def reverse_words(str) | |
| str.split.each { |word| word.reverse!}.join(' ') | |
| end |
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
| def addition item | |
| @list[item] ? @list[item] += 1 : @list[item] = 1 | |
| @list | |
| end |
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
| 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 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 | |
| def initialize(name, age, incoming_race) | |
| @name = name | |
| @age = age | |
| self.race = incoming_race | |
| end | |
| def nam | |
| @name.split.map(&:capitalize).join(" ") | |
| end |
OlderNewer