My initial confusion started when I looked at this code:
http://exercism.io/submissions/e3e0acc3148b4f42aed494485ccd0bb8
Specifically this bit
.collect::<String>() {
ref s if s.is_empty() => return num.to_string(),
s => s,
@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} |
# 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" |
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) |
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 |
class Bob | |
def reply_to(statement) | |
statement.reply(self) | |
rescue | |
default_reply | |
end | |
def reply_to_silence | |
"Fine. Be that way!" | |
end |
# 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 |
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 |
[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 |
# 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' |
My initial confusion started when I looked at this code:
http://exercism.io/submissions/e3e0acc3148b4f42aed494485ccd0bb8
Specifically this bit
.collect::<String>() {
ref s if s.is_empty() => return num.to_string(),
s => s,