Skip to content

Instantly share code, notes, and snippets.

var arr = []
function arrayOfLight(number) {
i = 0;
do {
arr.push(i);
i++;
}
while (i <= number);
return arr
#1.
SELECT isbn
FROM editions AS e
JOIN publishers AS p
ON e.publisher_id = p.id
WHERE p.name = 'Random House';
#2.
# A sample Gemfile
source "https://rubygems.org"
gem 'pry'
gem 'rspec'
### SETUP
require 'rspec'
### LOGIC (fix me)
def hello(who)
"hello " + who + "!"
end
### TEST CODE (don't touch me)
Create a Gist as a submission for this activity. Add a README.txt file to the Gist that includes a two to three paragraph explanation in your own words of how self refers to different objects depending on where it is in a Ruby program.
Self is an interesting object in the Ruby language. Depending on where the self is placed, self can
actually represent something completely different. If you were to call self on a class method, it means that the class itself can use that method.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for example:
# In this file we define the methods to help filter out candidates
# This way, we keep these methods separated from other potential parts of the program
class InvalidError < StandardError
end
def find(id)
unless @candidate.has_key?(:years_of_experience)
raise InvalidError, 'Candidate must have a :years_of_experience key'
end
@candidates.each do |candidate|
module Flight
def fly
puts "I'm a parrot, I'm flying!"
end
end
class Animal
attr_reader :name
def initialize(name)
@heart = 1
require 'rubygems'
require 'rest-client'
wiki_url = "http://en.wikipedia.org/"
wiki_local_file = "downloaded_wiki_page.html"
File.open(wiki_local_file, "w") do |file|
file.write(RestClient.get(wiki_url))
end
require 'colorize'
class Player
def initialize(name)
@name = name
@starting_life = 3
@starting_points = 0
end
def lose_life
@dollar = 0
@starting_caps = 0
@starting_bottles = 0
@left_over_caps = 0
@left_over_bottles = 0
@current_caps = 0
@current_bottles = 0
@new_soda_amount = 0
@current_soda = 0
@total_sodas = 0