Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
113ab607
Commit
113ab607
authored
Mar 14, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mruby-enumerator: move definitions in core_mod.rb to mrblib core
parent
463c5f83
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
108 deletions
+29
-108
mrbgems/mruby-enumerator/mrblib/core_mod.rb
mrbgems/mruby-enumerator/mrblib/core_mod.rb
+0
-98
mrblib/array.rb
mrblib/array.rb
+2
-0
mrblib/enum.rb
mrblib/enum.rb
+2
-0
mrblib/hash.rb
mrblib/hash.rb
+3
-1
mrblib/kernel.rb
mrblib/kernel.rb
+15
-6
mrblib/numeric.rb
mrblib/numeric.rb
+5
-3
mrblib/range.rb
mrblib/range.rb
+2
-0
No files found.
mrbgems/mruby-enumerator/mrblib/core_mod.rb
deleted
100644 → 0
View file @
463c5f83
##
# modifying existing methods
##
# See /mrblib/kernel.rb
module
Kernel
def
loop
return
to_enum
:loop
unless
block_given?
while
(
true
)
yield
end
rescue
=>
StopIteration
nil
end
end
# See /mrblib/numeric.rb
module
Integral
def
times
&
block
return
to_enum
:times
unless
block_given?
i
=
0
while
i
<
self
block
.
call
i
i
+=
1
end
self
end
end
# See /mrblib/enum.rb
module
Enumerable
def
collect
(
&
block
)
return
to_enum
:collect
unless
block_given?
ary
=
[]
self
.
each
{
|
val
|
ary
.
push
(
block
.
call
(
val
))
}
ary
end
alias
map
collect
end
# See /mrblib/array.rb
class
Array
def
each
(
&
block
)
return
to_enum
:each
unless
block_given?
idx
,
length
=
-
1
,
self
.
length
-
1
while
idx
<
length
and
length
<=
self
.
length
and
length
=
self
.
length
-
1
elm
=
self
[
idx
+=
1
]
unless
elm
if
elm
==
nil
and
length
>=
self
.
length
break
end
end
block
.
call
(
elm
)
end
self
end
end
# See /mrblib/hash.rb
class
Hash
def
each
(
&
block
)
return
to_enum
:each
unless
block_given?
self
.
keys
.
each
{
|
k
|
block
.
call
[
k
,
self
[
k
]]
}
self
end
end
# See /mrblib/range.rb
class
Range
def
each
&
block
return
to_enum
:each
unless
block_given?
val
=
self
.
first
unless
val
.
respond_to?
:succ
raise
TypeError
,
"can't iterate"
end
last
=
self
.
last
return
self
if
(
val
<=>
last
)
>
0
while
((
val
<=>
last
)
<
0
)
block
.
call
(
val
)
val
=
val
.
succ
end
if
not
exclude_end?
and
(
val
<=>
last
)
==
0
block
.
call
(
val
)
end
self
end
end
mrblib/array.rb
View file @
113ab607
...
...
@@ -10,6 +10,8 @@ class Array
#
# ISO 15.2.12.5.10
def
each
(
&
block
)
return
to_enum
:each
unless
block_given?
idx
,
length
=
-
1
,
self
.
length
-
1
while
idx
<
length
and
length
<=
self
.
length
and
length
=
self
.
length
-
1
elm
=
self
[
idx
+=
1
]
...
...
mrblib/enum.rb
View file @
113ab607
...
...
@@ -78,6 +78,8 @@ module Enumerable
#
# ISO 15.3.2.2.3
def
collect
(
&
block
)
return
to_enum
:collect
unless
block_given?
ary
=
[]
self
.
each
{
|
val
|
ary
.
push
(
block
.
call
(
val
))
...
...
mrblib/hash.rb
View file @
113ab607
...
...
@@ -43,7 +43,9 @@ class Hash
#
# ISO 15.2.13.4.9
def
each
(
&
block
)
self
.
keys
.
each
{
|
k
|
block
.
call
([
k
,
self
[
k
]])}
return
to_enum
:each
unless
block_given?
self
.
keys
.
each
{
|
k
|
block
.
call
[
k
,
self
[
k
]]
}
self
end
...
...
mrblib/kernel.rb
View file @
113ab607
...
...
@@ -18,11 +18,12 @@ module Kernel
# Calls the given block repetitively.
#
# ISO 15.3.1.2.8
def
self
.
loop
#(&block)
while
(
true
)
yield
end
end
# provided by Kernel#loop
# def self.loop #(&block)
# while(true)
# yield
# end
# end
# 15.3.1.2.3
def
self
.
eval
(
s
)
...
...
@@ -38,14 +39,22 @@ module Kernel
# Alias for +Kernel.loop+.
#
# ISO 15.3.1.3.29
def
loop
#(&block)
def
loop
return
to_enum
:loop
unless
block_given?
while
(
true
)
yield
end
rescue
=>
StopIteration
nil
end
# 11.4.4 Step c)
def
!~
(
y
)
!
(
self
=~
y
)
end
def
to_enum
(
*
a
)
raise
NotImplementedError
.
new
(
"fiber required for enumerator"
)
end
end
mrblib/numeric.rb
View file @
113ab607
...
...
@@ -67,10 +67,12 @@ module Integral
# Calls the given block +self+ times.
#
# ISO 15.2.8.3.22
def
times
(
&
block
)
def
times
&
block
return
to_enum
:times
unless
block_given?
i
=
0
while
(
i
<
self
)
block
.
call
(
i
)
while
i
<
self
block
.
call
i
i
+=
1
end
self
...
...
mrblib/range.rb
View file @
113ab607
...
...
@@ -10,6 +10,8 @@ class Range
#
# ISO 15.2.14.4.4
def
each
(
&
block
)
return
to_enum
:each
unless
block_given?
val
=
self
.
first
unless
val
.
respond_to?
:succ
raise
TypeError
,
"can't iterate"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment