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
# car loan calculator | |
# methods | |
def prompt(message) | |
puts("=>#{message}") | |
end | |
def number_valid(num) | |
num =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/ | |
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
# car loan calculator | |
def prompt(message) | |
puts("=>#{message}") | |
end | |
def number_valid(num) | |
num =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/ | |
end | |
def integer?(input) |
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 prompt(message) | |
puts("=>#{message}") | |
end | |
GAME = %w(rock paper scissors lizard spoke) | |
def shorten_input(input) | |
case input | |
when "p" , "P" , "paper" | |
input = "paper" |
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 prompt(message) | |
puts("=>#{message}") | |
end | |
GAME = %w(rock paper scissors lizard spoke) | |
def shorten(input) | |
case input | |
when "p" , "P" , "paper" | |
input = "paper" |
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
``` ruby | |
BOARD = ["a1" , "a2" , "a3" , "b1" , "b2" , "b3" , "c1" , "c2" , "c3"] | |
MARKER =[] | |
user_array = [] | |
computer_array = [] | |
def prompt(message) | |
puts message | |
end | |
def win?(player_array) |
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
arr1 = [1,2,3,4] | |
arr2 = ['a', 'b', 'c', 'd'] | |
def interleave(arr1, arr2) | |
newarr = [] | |
arr1.each do |num| | |
newarr << num << arr2[arr1.index(num)] | |
end | |
p newarr | |
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
I reviewed some common Ruby methods and grouped them by behavior. | |
Hopefully this helps someone else too. | |
[Please copy paste and fix typos, add/delete, improve from this Gist.](https://gist.github.com/dirkdirk/9209d7ea67ac57543975162713910224) | |
- | |
# Array |
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
# Sample implementation of quicksort and mergesort in ruby | |
# Both algorithm sort in O(n * lg(n)) time | |
# Quicksort works inplace, where mergesort works in a new array | |
def quicksort(array, from=0, to=nil) | |
if to == nil | |
# Sort the whole array, by default | |
to = array.count - 1 | |
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 Move | |
attr_accessor :value | |
VALID_CHOICES = ["rock", "paper", "scissors", "lizard", "spoke"] | |
def initialize(value) | |
@value = value | |
end | |
def to_s | |
@value | |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>your page title goes here</title> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
</body> | |
</html> |
OlderNewer