3 ms·
Ruby's Struct is pretty nifty. Person = Struct.new :name, :age people = [ Person.new('Alice', 42), Person.new('Bob', 23), Person.n
by 0x0dea 11y ago
Ruby's Struct is pretty nifty.
Person = Struct.new :name, :age
people = [
Person.new('Alice', 42),
Person.new('Bob', 23),
Person.new('Carol', 30)
]
people.sort_by(&:age).map(&:name)
# => ["Bob", "Carol", "Alice"]