Last active
August 29, 2015 14:13
-
-
Save gregstewart/fae1a7be9d2fbbea5fb6 to your computer and use it in GitHub Desktop.
Playing with blocks and partition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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