Last active
February 23, 2016 17:14
-
-
Save zentetsukenz/30bb789653aa2fdf50df to your computer and use it in GitHub Desktop.
Ruby sum array of object map reduce style
This file contains hidden or 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 A | |
attr_accessor :name, :value | |
def initialize | |
@value = rand(10) | |
@name = "Mr. #{@value}_#{rand(100)}" | |
end | |
end | |
a = Array.new(10).collect { |e| e = A.new } | |
a.map(&:value).inject(&:+) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment