Code Explainers
Code explainers tagged #enumerable
ruby
module FixedWidthParser FIELDS = [ { name: :record_type, range: 0...2 }, { name: :account_id, range: 2...12, type: :integer },
Parsing fixed-width records in Ruby
parsing
data-driven-design
type-coercion
Intermediate
5 steps
ruby
class DateRangeMerger def initialize(ranges) @ranges = ranges end
Merging overlapping date ranges in Ruby
sorting
interval-merging
enumerable
Intermediate
5 steps
ruby
require "forwardable" class ShoppingCart extend Forwardable
Delegation in Ruby with Forwardable
delegation
composition
enumerable
Intermediate
9 steps
ruby
class ContactImporter def initialize(rows) @rows = rows end
Deduplicating contacts with Enumerable#uniq
deduplication
normalization
enumerable
Intermediate
4 steps
ruby
class MetricSeries def initialize(readings, window: 5) @readings = readings @window = window
Rolling averages with each_cons in Ruby
sliding-window
enumerable
data-smoothing
Intermediate
7 steps
ruby
require "csv" class SalesReport def initialize(path)
Aggregating CSV sales data in Ruby
data-aggregation
memoization
group_by
Intermediate
6 steps
ruby
module TextAnalysis module_function WORD_PATTERN = /[\p{Alpha}']+/
Building a word-frequency analyzer in Ruby
text processing
regex
enumerable
Intermediate
8 steps
ruby
class LinkedList include Enumerable Node = Struct.new(:value, :next_node)
Building an enumerable linked list in Ruby
linked-list
enumerable
data-structures
Intermediate
7 steps