Skip to content

Instantly share code, notes, and snippets.

@rafer
rafer / gist:920434
Created April 14, 2011 20:27
ROB 4/14/2011 Trivia: Question 7
# Question 7.
# What happens when you run the following?
p x
# And what happens when you run the following?
x = 5 if false
p x
@rafer
rafer / gist:920427
Created April 14, 2011 20:26
ROB 4/14/2011 Trivia: Question 6
# Question 6. What does the following print?
module A
def horses
puts "Called in Module A"
end
end
module B
include A
@rafer
rafer / gist:920423
Created April 14, 2011 20:25
ROB 4/14/2011 Trivia: Question 5
# Question 5. What's the output of the following?
def lambdicate
print "A"
lambda { return }.call
print "B"
end
def proctify
print "A"
@rafer
rafer / gist:920414
Created April 14, 2011 20:24
ROB 4/14/2011 Trivia: Question 4
# Question 4. What does the following print
p [:a, :b][2,1]
p [:a, :b][3,1]
@rafer
rafer / gist:920410
Created April 14, 2011 20:23
ROB 4/14/2011 Trivia: Question 3
# Question 3. What does the following print?
p [String === "String", "String" === String]
p ["String".equal?("String"), "String".eql?("String"), "String" == "String"]
@rafer
rafer / gist:920399
Created April 14, 2011 20:19
ROB 4/14/2011 Trivia: Question 2
# Question 2: What does the following print?
class Bob
class << self
puts self.name
end
end
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.
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)
# 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)
def model_exists?
begin
potential_model = yield
return ActiveRecord::Base.send(:subclasses).include?(potential_model)
rescue NameError
return false
end
end