Skip to content

Commit 9afd844

Browse files
authored
Add files via upload
1 parent 163a829 commit 9afd844

File tree

9 files changed

+90
-0
lines changed

9 files changed

+90
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def my_all
2+
a = true
3+
self.my_each do |e|
4+
if yield(e) == false
5+
a = false
6+
end
7+
end
8+
a
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def my_any?
2+
a = false
3+
self.my_each do |e|
4+
if yield(e) == true
5+
a = true
6+
end
7+
end
8+
a
9+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def my_count
2+
c = 0
3+
self.my_each do |e|
4+
if block_given?
5+
c += 1 if yield(e) == true
6+
else
7+
c += 1
8+
end
9+
end
10+
c
11+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def my_each
2+
if self.class == Hash
3+
keys.each do |k|
4+
val = self[k]
5+
yield(k, val)
6+
end
7+
else
8+
each do |i|
9+
yield i
10+
end
11+
end
12+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def my_each_with_index
2+
i = 0
3+
for a in self
4+
yield(a, i)
5+
i = i + 1
6+
end
7+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def my_inject(store=self[])
2+
store ||= []
3+
self.my_each do |e|
4+
store = yield(store, e)
5+
end
6+
store
7+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def my_map()
2+
mapping = []
3+
if block_given?
4+
self.my_each do |e|
5+
mapping.push(yield(e))
6+
end
7+
else
8+
self.my_each do |e|
9+
mapping.push(proc.call(e))
10+
end
11+
end
12+
mapping
13+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def my_none?
2+
a = true
3+
self.my_each do |e|
4+
if yield(e) == true
5+
a = false
6+
end
7+
end
8+
a
9+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def my_select
2+
if self.class == Array
3+
ss = []
4+
end
5+
if self.class == Hash
6+
ss = {}
7+
end
8+
9+
self.my_each do |e|
10+
ss.push(e) if yield(e)
11+
end
12+
ss
13+
end

0 commit comments

Comments
 (0)