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
8808c9a3
Commit
8808c9a3
authored
Apr 06, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrap args by parens
parent
d016059b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
mrbgems/mruby-enumerator/mrblib/enumerator.rb
mrbgems/mruby-enumerator/mrblib/enumerator.rb
+12
-12
No files found.
mrbgems/mruby-enumerator/mrblib/enumerator.rb
View file @
8808c9a3
...
@@ -110,7 +110,7 @@ class Enumerator
...
@@ -110,7 +110,7 @@ class Enumerator
#
#
# p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
# p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
#
#
def
initialize
obj
=
nil
,
meth
=
:each
,
*
args
,
&
block
def
initialize
(
obj
=
nil
,
meth
=
:each
,
*
args
,
&
block
)
if
block_given?
if
block_given?
obj
=
Generator
.
new
(
&
block
)
obj
=
Generator
.
new
(
&
block
)
else
else
...
@@ -129,7 +129,7 @@ class Enumerator
...
@@ -129,7 +129,7 @@ class Enumerator
attr_accessor
:obj
,
:meth
,
:args
,
:fib
attr_accessor
:obj
,
:meth
,
:args
,
:fib
private
:obj
,
:meth
,
:args
,
:fib
private
:obj
,
:meth
,
:args
,
:fib
def
initialize_copy
obj
def
initialize_copy
(
obj
)
raise
TypeError
,
"can't copy type
#{
obj
.
class
}
"
unless
obj
.
kind_of?
Enumerator
raise
TypeError
,
"can't copy type
#{
obj
.
class
}
"
unless
obj
.
kind_of?
Enumerator
raise
TypeError
,
"can't copy execution context"
if
obj
.
fib
raise
TypeError
,
"can't copy execution context"
if
obj
.
fib
@obj
=
obj
.
obj
@obj
=
obj
.
obj
...
@@ -152,7 +152,7 @@ class Enumerator
...
@@ -152,7 +152,7 @@ class Enumerator
#
#
# +offset+:: the starting index to use
# +offset+:: the starting index to use
#
#
def
with_index
offset
=
0
def
with_index
(
offset
=
0
)
return
to_enum
:with_index
,
offset
unless
block_given?
return
to_enum
:with_index
,
offset
unless
block_given?
raise
TypeError
,
"no implicit conversion of
#{
offset
.
class
}
into Integer"
unless
offset
.
respond_to?
(
:to_int
)
raise
TypeError
,
"no implicit conversion of
#{
offset
.
class
}
into Integer"
unless
offset
.
respond_to?
(
:to_int
)
...
@@ -205,8 +205,8 @@ class Enumerator
...
@@ -205,8 +205,8 @@ class Enumerator
# # => foo:1
# # => foo:1
# # => foo:2
# # => foo:2
#
#
def
with_object
object
def
with_object
(
object
)
return
to_enum
:with_object
,
object
unless
block_given?
return
to_enum
(
:with_object
,
object
)
unless
block_given?
enumerator_block_call
do
|
i
|
enumerator_block_call
do
|
i
|
yield
[
i
,
object
]
yield
[
i
,
object
]
...
@@ -262,7 +262,7 @@ class Enumerator
...
@@ -262,7 +262,7 @@ class Enumerator
# enum.each(:y, :z).equal?(enum) #=> false
# enum.each(:y, :z).equal?(enum) #=> false
# enum.each(:y, :z) { |elm| elm } #=> :method_returned
# enum.each(:y, :z) { |elm| elm } #=> :method_returned
#
#
def
each
*
argv
,
&
block
def
each
(
*
argv
,
&
block
)
obj
=
self
obj
=
self
if
0
<
argv
.
length
if
0
<
argv
.
length
obj
=
self
.
dup
obj
=
self
.
dup
...
@@ -512,7 +512,7 @@ class Enumerator
...
@@ -512,7 +512,7 @@ class Enumerator
# e.next # (7)
# e.next # (7)
# # (10)
# # (10)
#
#
def
feed
value
def
feed
(
value
)
raise
TypeError
,
"feed value already set"
if
@feedvalue
raise
TypeError
,
"feed value already set"
if
@feedvalue
@feedvalue
=
value
@feedvalue
=
value
nil
nil
...
@@ -520,13 +520,13 @@ class Enumerator
...
@@ -520,13 +520,13 @@ class Enumerator
# just for internal
# just for internal
class
Generator
class
Generator
def
initialize
&
block
def
initialize
(
&
block
)
raise
TypeError
,
"wrong argument type
#{
self
.
class
}
(expected Proc)"
unless
block
.
kind_of?
Proc
raise
TypeError
,
"wrong argument type
#{
self
.
class
}
(expected Proc)"
unless
block
.
kind_of?
Proc
@proc
=
block
@proc
=
block
end
end
def
each
*
args
,
&
block
def
each
(
*
args
,
&
block
)
args
.
unshift
Yielder
.
new
(
&
block
)
args
.
unshift
Yielder
.
new
(
&
block
)
@proc
.
call
(
*
args
)
@proc
.
call
(
*
args
)
end
end
...
@@ -534,13 +534,13 @@ class Enumerator
...
@@ -534,13 +534,13 @@ class Enumerator
# just for internal
# just for internal
class
Yielder
class
Yielder
def
initialize
&
block
def
initialize
(
&
block
)
raise
LocalJumpError
,
"no block given"
unless
block_given?
raise
LocalJumpError
,
"no block given"
unless
block_given?
@proc
=
block
@proc
=
block
end
end
def
yield
*
args
def
yield
(
*
args
)
@proc
.
call
(
*
args
)
@proc
.
call
(
*
args
)
end
end
...
@@ -610,7 +610,7 @@ module Kernel
...
@@ -610,7 +610,7 @@ module Kernel
# # => returns an Enumerator when called without a block
# # => returns an Enumerator when called without a block
# enum.first(4) # => [1, 1, 1, 2]
# enum.first(4) # => [1, 1, 1, 2]
#
#
def
to_enum
meth
=
:each
,
*
args
def
to_enum
(
meth
=
:each
,
*
args
)
Enumerator
.
new
self
,
meth
,
*
args
Enumerator
.
new
self
,
meth
,
*
args
end
end
alias
:enum_for
:to_enum
alias
:enum_for
:to_enum
...
...
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