Skip to content

Instantly share code, notes, and snippets.

function arrayOfLight(x) {
var arr = [];
var i = 0;
while (x--) {
arr.push(i++);
}
return arr;
}
class Comment
attr_reader :user_name, :comment
def initialize(user_name, comment)
@user_name = user_name
@copy = copy
end
def to_s
class SiegeEngine < Unit
attr_reader :health_points, :attack_points
def initialize
super(400, 50)
end
def attack_barracks(barrack)
barrack.damage(@attack_points * 2)
@natsanjuro
natsanjuro / Question
Created September 25, 2015 21:45
2 player game using classes
class Question
attr_accessor :num1, :num2, :answer
attr_reader :random_operator
def initialize
@num1 = rand(1..100)
@num2 = rand(1..100)
@operator = ['+', '-', '*']
@random_operator = @operator.sample
require 'colorize'
@player1_lives = 3
@player2_lives = 3
@current_player = 1
def begin_round
@num_1 = rand(1..100)
@num_2 = rand(1..100)
def merge_sort(array)
return array if array.length <= 1
left = merge_sort array[0, array.length / 2]
right = merge_sort array [array.length / 2, array.length]
merge(left, right)
end
def merge(left, right)
result = []
require 'pg'
class Contacts
attr_accessor :firstname, :lastname, :email
attr_reader :id
def initialize(firstname, lastname, email, id=nil)
@firstname = firstname
@lastname = lastname
1.
heroku-postgres-fe6007ec::CHARCOAL=>
SELECT p.id, e.isbn, p.name
FROM publishers
AS p JOIN editions
AS e ON e.publisher_id = p.id
WHERE p.name = 'Random House';
id | isbn | name
puts "What is the height?"
user_input_height = gets.chomp.to_i
puts "What is the width?"
user_input_width = gets.chomp.to_i
puts "How many colours?"
user_input_colour = gets.chomp.to_i
squarefeet = user_input_height * user_input_width
require './animal.rb'
class Amphibian < Animal
end