Skip to content

Instantly share code, notes, and snippets.

@zentetsukenz
Last active February 23, 2016 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zentetsukenz/30bb789653aa2fdf50df to your computer and use it in GitHub Desktop.
Save zentetsukenz/30bb789653aa2fdf50df to your computer and use it in GitHub Desktop.
Ruby sum array of object map reduce style
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