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
# Should the contestant switch to the other door? | |
@switch = true | |
@wins = 0; @losses = 0 | |
100000.times do | |
# Hide the car | |
car_behind = rand(3) | |
# Contestant picks a door | |
contestant_pick = rand(3) |
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
def model_exists?(model_name) | |
begin | |
potential_model = model_name.constantize | |
rescue NameError | |
return false | |
end | |
ActiveRecord::Base.send(:subclasses).include?(potential_model) | |
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
def model_exists? | |
begin | |
potential_model = yield | |
return ActiveRecord::Base.send(:subclasses).include?(potential_model) | |
rescue NameError | |
return false | |
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
# A mixin that makes a record "seeable" by users. | |
module Seeable | |
def self.included(base) | |
base.has_many :seeings, :as => :thing | |
end | |
# Note that user seeing this thing (now) | |
# Returns true if the user has previously seen the object, and false otherwise | |
# essentially the same as doing a seen_by? before noting the new seeing. | |
def seen_by!(user) |
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 ModelExtensionLoader | |
def self.activate! | |
class << ActiveRecord::Base | |
alias_method :old_inherited, :inherited | |
def inherited(model) | |
puts "Trying to load extensions #{model} extensions" | |
if extension = ModelExtensionLoader.safe_constantize("Extensions::#{model}") | |
model.send(:include, extension) |
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
Rafer Hazen: It seems like I used to be able to SSH in to their account, and now I cannot. I have a working username and password. | |
Harriet Anderson: I apologize for any inconvenience this has caused you. | |
Harriet Anderson: To protect your account from unauthorized changes, can you please verify for me the answer to the Security Question: | |
Harriet Anderson: What is your pet's name? | |
Rafer Hazen: The client never gave me that information. |
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
# Question 2: What does the following print? | |
class Bob | |
class << self | |
puts self.name | |
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
# Question 3. What does the following print? | |
p [String === "String", "String" === String] | |
p ["String".equal?("String"), "String".eql?("String"), "String" == "String"] |
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
# Question 4. What does the following print | |
p [:a, :b][2,1] | |
p [:a, :b][3,1] |
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
# Question 5. What's the output of the following? | |
def lambdicate | |
print "A" | |
lambda { return }.call | |
print "B" | |
end | |
def proctify | |
print "A" |
OlderNewer