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
require "sqlite3" | |
require 'open-uri' | |
require 'nokogiri' | |
############### | |
# # Open a database | |
db = SQLite3::Database.new "students.db" | |
rows = db.execute <<-SQL |
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
module Enumberable | |
a = {:key => nil, :other_key => "value" } | |
def flatiron_flatten | |
self.select do |key, value| | |
value!=nil | |
end | |
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
index = 0 | |
stopper = false | |
until stopper == true | |
counter = 0 | |
index+= 19 | |
(1..20).each do |num| | |
if index % num == 0 | |
counter += 1 | |
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
app.rb | |
require 'rack' | |
class MyApp | |
def call(env) | |
puts "Hello from MyApp!" | |
[200, {}, ["Hello"]] | |
end | |
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
require 'rack' | |
class AdamApp #change this name | |
def call(env) | |
[200, {'Content-Type' => 'text/html'}, | |
['<a href="http://students.flatironschool.com/students/awaxman.html"><h1 style="color:blue">Adam Waxman<h1></a>'] | |
] | |
end | |
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 School | |
attr_accessor :name, :roster | |
def initialize(name) | |
@name = name | |
@roster = {} | |
end | |
def add_student(name, grade) | |
student = Student.new |
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 School | |
attr_accessor :name, :roster | |
def initialize(name) | |
@name = name | |
@roster = {} | |
end | |
def add_student(name, grade) | |
student = Student.new |
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
# reverse_each_word.rb | |
# Write a method that takes a sentence and returns it with each word reversed in place. | |
# A String has many methods that can be called on it: | |
# http://www.ruby-doc.org/core-1.9.3/String.html | |
sentence = "Hello there, and how are you?" | |
def reverse_each_word(sentence) | |
sentence.split.collect { |word| word.reverse}.join(" ") |
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
require "sqlite3" | |
require 'open-uri' | |
require 'nokogiri' | |
############### | |
# # Open a database | |
db = SQLite3::Database.new "test.db" | |
rows = db.execute <<-SQL |
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
# jukebox.rb | |
# list, play, help, exit | |
class Jukebox | |
attr_accessor :songs | |
def start |