Skip to content

Instantly share code, notes, and snippets.

@gregstewart
Last active August 29, 2015 14:13
Show Gist options
  • Save gregstewart/fae1a7be9d2fbbea5fb6 to your computer and use it in GitHub Desktop.
Save gregstewart/fae1a7be9d2fbbea5fb6 to your computer and use it in GitHub Desktop.
Playing with blocks and partition
class Order
attr_accessor :size, :value
def initialize size, value
@size = size
@value = value
end
end
orders = []
1.upto 5 do | n |
orders << Order.new(10*n, 100*n)
end
puts "all orders"
puts orders.inspect
small_orders, large_orders = orders.partition { |o| o.value <= 200 }
puts "small orders"
puts small_orders.inspect
puts "large orders"
puts large_orders.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment