Code Explainers
Code explainers tagged #struct
ruby
class UserAgentParser BROWSERS = [ [/Edg\/([\d.]+)/, "Edge"], [/OPR\/([\d.]+)/, "Opera"],
Parsing user-agent strings in Ruby
regex
pattern-matching
lookup-tables
Intermediate
8 steps
ruby
class ActivityFeed include Enumerable Entry = Struct.new(:record, :type, :occurred_at, keyword_init: true) do
Building a paginated activity feed in Rails
enumerable
pagination
composition
Intermediate
9 steps
ruby
class WeatherLookup Result = Struct.new(:temperature, :conditions, keyword_init: true) class TimeoutError < StandardError; end
A resilient weather API service object in Rails
service-object
http-client
error-handling
Intermediate
7 steps
ruby
class HashDiff Change = Struct.new(:from, :to) def self.call(before, after)
Diffing two hashes in Ruby
set-operations
struct
enumerable
Intermediate
7 steps