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
irb(main):001:0> a = ["hello", "there"] | |
=> ["hello", "there"] | |
irb(main):002:0> a.map { |w| w.include?[^Chere"]} | |
irb(main):002:0> a | |
=> ["hello", "there"] | |
irb(main):003:0> b = ["there"] | |
=> ["there"] | |
irb(main):004:0> a.map { |w| b.include?(w) ? "<b>#{w}</b>" : w } | |
=> ["hello", "<b>there</b>"] | |
irb(main):005:0> a |
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 Nokogiri | |
module XML | |
module SAX | |
class PushParser | |
# The Nokogiri::XML::SAX::Document on which the PushParser will be | |
# operating | |
attr_accessor :document | |
### |
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
secret = rand(100) | |
print "Enter a number..." | |
while secret != (input = gets.chomp.strip.to_i) | |
puts "Wrong. Guess again..." | |
if secret > input | |
puts "I'll give you a clue... its higher..." | |
else | |
puts "I'll give you a clue... its lower..." |
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
print "Hello, what is your name ? > " | |
first_name = gets.strip.chomp | |
puts "Hello #{first_name}" | |
# Do the same thing for the second name | |
print "Ok, what is your second name ? >" | |
last_name = gets.strip.chomp | |
puts "Your full name is : #{first_name} #{last_name}" | |
# Ask the user for their age, and say that they can't come |
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 'rubygems' | |
require 'pry' | |
class Animal | |
def speak | |
puts "hello" | |
end | |
def self.create_animal(type) | |
case type |
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 'rubygems' | |
require 'yaml' | |
class Person | |
attr_accessor :name | |
attr_accessor :email | |
attr_accessor :github_user | |
attr_accessor :twitter | |
attr_accessor :fun_fact | |
attr_accessor :favorite_food |
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
# Let's make @directory an array, rather than a String | |
@directory = [] | |
# Pull in existing people from a YAML file | |
@directory += YAML.load_documents(File.open('student_directory.yml')) | |
# Save people to a YAML file | |
File.open('student_directory.yml', 'a') { |f| | |
@directory.compact.each do |person| | |
f.write(person.to_yaml) |
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 'pry' | |
require 'sqlite3' | |
# Open a database called my_amazing_database.db | |
# and store a reference to it in db | |
db = SQLite3::Database.new("my_amazing_database.db") | |
# Print all of the people in the database so far | |
results = db.execute("select * from people") | |
results.each do |row| |
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 'sinatra' | |
set :urls, { | |
:xyz => "http://www.generalassemb.ly" | |
} | |
get '/:short_url' do | |
full_url = settings.urls[params[:short_url].to_sym] | |
if full_url | |
redirect full_url |
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 'test/unit' | |
require 'rack/test' | |
require_relative '../movie_server' | |
class MovieServerTest < Test::Unit::TestCase | |
include Rack::Test::Methods | |
def app | |
Sinatra::Application | |
end |
OlderNewer