jakehow (owner)

Revisions

gist: 97299 Download_button fork
public
Public Clone URL: git://gist.github.com/97299.git
Embed All Files: show embed
modular-restriction #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Array
  def sum
    inject(0) {|total,n| total + n }
  end
end
 
puts Array.new([1,2,3,4]).sum
puts [1,2,3,4].sum
 
module StickyFingaz
  class Array < ::Array
    def sum
      # I always keep one for myself
      inject(0) {|total,n| total + n } - 1
    end
  end
  puts Array.new([1,2,3,4]).sum
  puts [1,2,3,4].sum
end
 
module LazyFool
  class Array < ::Array
    def sum
      # You can teach a man to fish...
      lambda { inject(0) {|total,n| total + n } }
    end
  end
  
  puts Array.new([1,2,3,4]).sum
  puts [1,2,3,4].sum
end