@@ -30,8 +30,8 @@ def my_all?(a=nil)
30
30
31
31
def my_any? ( a = nil )
32
32
my_each { |x | return yield ( x ) ? true : false } if block_given?
33
- my_each { |x | return a . match ( x . to_s ) ? true : false } if a . class == Regexp
34
- my_each { |x | return x . is_a? ( a ) ? true : false } if a . class == Class
33
+ my_each { |x | return a . match ( x . to_s ) ? true : false } if a . class == Regexp
34
+ my_each { |x | return x . is_a? ( a ) ? true : false } if a . class == Class
35
35
my_each { |x | return x ? true : false } unless block_given?
36
36
end
37
37
@@ -61,8 +61,8 @@ def my_map
61
61
62
62
def my_inject ( a = nil , b = nil )
63
63
a . class == Numeric ? final = a : final = 0
64
- b = a if a != nil && b . nil?
65
- if b != nil || b != false
64
+ b = a if ! a . nil? && b . nil?
65
+ if ! b . nil? || b != false
66
66
case b
67
67
when :+
68
68
my_each { |y | final += y }
@@ -72,21 +72,19 @@ def my_inject(a=nil,b=nil)
72
72
return final
73
73
when :*
74
74
final = 1 if final != 0
75
- my_each { |y | final *= y }
75
+ my_each { |y | final *= y }
76
76
return final
77
77
when :/
78
78
my_each { |y | final /= y }
79
79
return final
80
80
end
81
81
end
82
- if block_given?
83
- final = 1 if yield ( final , self [ 0 ] ) == 0 || yield ( final , self [ 1 ] ) == 0 if self [ 1 ] != nil
84
- my_each { |x | final = yield ( final , x ) }
85
- return final
86
- end
82
+ final = 1 if yield ( final , self [ 0 ] ) == 0 || yield ( final , self [ 1 ] ) == 0 if self [ 1 ] != nil if block_given?
83
+ my_each { |x | final = yield ( final , x ) } if block_given?
84
+ return final if block_given?
87
85
end
88
86
end
89
87
90
88
def multiply_els ( x )
91
- x . my_inject ( :+ )
92
- end
89
+ x . my_inject ( :* )
90
+ end
0 commit comments