This file contains hidden or 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
# Referenced in Design Is Refactoring post http://designisrefactoring.com/2016/02/03/factories/ | |
# This code takes the previous example and extends it. Classes can now define 'roles' they satisfy | |
# and each class can satisfy more than one role. | |
# | |
# At load time, these roles are examined and recorded in registries. | |
# In this example there's a CampusLikeRegistry that contains every class that says it's campus-like. | |
# But you could have any number of registries. | |
require 'singleton' | |
require 'forwardable' |
This file contains hidden or 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
[1,2,3][3] | |
#=> nil | |
# Ask for element outside of the array, get nil. cool. | |
[1,2,3][3,1] | |
#=> [] | |
#=> Ask for a 1-element slice that starts outside of the array, get an empty array. Ok? | |
[1,2,3][4] | |
#=> nil |
This file contains hidden or 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
receipt_id = _your_receipt_id_ | |
r = Etl::Receipt.find(receipt_id) | |
r.audits.each do |a| | |
Etl::Audit::Facet.all_classes.each do |f| | |
f.where(etl_audit_id: a.id).delete_all | |
end | |
end | |
s = Etl::Service.new(r) | |
s.extract_facets |
This file contains hidden or 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
# From the docs of Kernel.array | |
# First tries to call to_ary on arg, then to_a. | |
# http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-Array | |
# Ok, so does a struct respond to to_ary? | |
Monkey = Struct.new(:name, :favorite_color) | |
m = Monkey.new("George", "Yellow") | |
m.respond_to?(:to_ary) | |
#=> false |
This file contains hidden or 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 Bob | |
def reply_to(statement) | |
statement.reply(self) | |
rescue | |
default_reply | |
end | |
def reply_to_silence | |
"Fine. Be that way!" | |
end |
This file contains hidden or 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 Bob | |
def reply_to(statement) | |
public_send("reply_to_#{statement.class}".downcase.to_sym) | |
rescue NoMethodError | |
default_reply | |
end | |
def reply_to_silence | |
"Fine. Be that way!" | |
end |
This file contains hidden or 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
GIT | |
remote: git://github.com/rails/rails.git | |
revision: 5d543c5996da986ba8d979cd83236e130a3bd953 | |
tag: v4.2.0.rc1 | |
specs: | |
actionmailer (4.2.0.rc1) | |
actionpack (= 4.2.0.rc1) | |
actionview (= 4.2.0.rc1) | |
activejob (= 4.2.0.rc1) | |
mail (~> 2.5, >= 2.5.4) |
This file contains hidden or 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
# Array of an openstruct works as you'd expect, but to_a does not. | |
# OpenStruct descends from Object, Kernel, BasicObject. None of which implement to_a. So that explains that. | |
# I'm a little unclear on why Array(os) is working. Array(Object.new) works, and OpenStruct descends directly from Object. | |
# BUT, the Array docs say that it calls .to_ary or .to_a on the argument, and an OpenStruct instance responds to neither of those. | |
# So....? | |
require 'ostruct' | |
#=> true | |
os = OpenStruct.new | |
#=> #<OpenStruct> | |
os.prop1 = "test" |
This file contains hidden or 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
@athlete = Athlete.find(4329615) | |
@active_progs = @athlete.future_complete_academic_program_memberships.all(:conditions => "prog_status in ('AC', 'CM')") | |
@old_progs = @athlete.future_complete_academic_program_memberships.all(:conditions => "prog_status not in ('AC', 'CM')", :order => "action_dt desc") | |
@academic_tree_paths = @athlete.future_academic_tree_paths | |
prog = @active_progs.first | |
@academic_tree_paths.detect { |tp| tp.ps_acad_prog_stdnt_car_nbr == prog.stdnt_car_nbr && tp.ps_acad_prog_acad_career == prog.acad_career} |
This file contains hidden or 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
x = Hash.new{|h,k| h[k] = []} |