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
7e4c5457
Commit
7e4c5457
authored
May 03, 2012
by
Yukihiro Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:mruby/mruby
parents
0c6bd79d
da9fa234
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
13 deletions
+68
-13
mrblib/array.rb
mrblib/array.rb
+33
-8
mrblib/print.rb
mrblib/print.rb
+14
-0
mrblib/struct.rb
mrblib/struct.rb
+21
-5
No files found.
mrblib/array.rb
View file @
7e4c5457
#
#
#
# Array
#
# ISO 15.2.12
class
Array
# 15.2.12.5.10
##
# Calls the given block for each element of +self+
# and pass the respective element.
#
# ISO 15.2.12.5.10
def
each
(
&
block
)
idx
=
0
while
(
idx
<
length
)
...
...
@@ -12,7 +18,11 @@ class Array
self
end
# 15.2.12.5.11
##
# Calls the given block for each element of +self+
# and pass the index of the respective elment.
#
# ISO 15.2.12.5.11
def
each_index
(
&
block
)
idx
=
0
while
(
idx
<
length
)
...
...
@@ -22,7 +32,12 @@ class Array
self
end
# 15.2.12.5.7
##
# Calls the given block for each element of +self+
# and pass the respective element. Each element will
# be replaced by the resulting values.
#
# ISO 15.2.12.5.7
def
collect!
(
&
block
)
self
.
each_index
{
|
idx
|
self
[
idx
]
=
block
.
call
(
self
[
idx
])
...
...
@@ -30,11 +45,16 @@ class Array
self
end
# 15.2.12.5.20
# map!(&block)
##
# Alias for collect!
#
# ISO 15.2.12.5.20
alias
map!
collect!
# 15.2.12.5.15
##
# Private method for Array creation.
#
# ISO 15.2.12.5.15
def
initialize
(
size
=
0
,
obj
=
nil
,
&
block
)
raise
TypeError
,
"expected Integer for 1st argument"
unless
size
.
kind_of?
Integer
raise
ArgumentError
,
"negative array size"
if
size
<
0
...
...
@@ -53,6 +73,8 @@ class Array
self
end
##
# Delete element with index +key+
def
delete
(
key
,
&
block
)
while
i
=
self
.
index
(
key
)
self
.
delete_at
(
i
)
...
...
@@ -73,6 +95,9 @@ class Array
include
Enumerable
include
Comparable
##
# Sort all elements and replace +self+ with these
# elements.
def
sort!
(
&
block
)
self
.
replace
(
self
.
sort
(
&
block
))
end
...
...
mrblib/print.rb
View file @
7e4c5457
##
# Kernel
#
# ISO 15.3.1
module
Kernel
##
# Invoke method +print+ on STDOUT and passing +*args+
#
# ISO 15.3.1.2.10
def
print
(
*
args
)
i
=
0
len
=
args
.
size
...
...
@@ -7,6 +16,11 @@ module Kernel
i
+=
1
end
end
##
# Invoke method +puts+ on STDOUT and passing +*args*+
#
# ISO 15.3.1.2.11
def
puts
(
*
args
)
i
=
0
len
=
args
.
size
...
...
mrblib/struct.rb
View file @
7e4c5457
#
#
#
# Struct
#
# ISO 15.2.18
class
Struct
# 15.2.18.4.4
##
# Calls the given block for each element of +self+
# and pass the respective element.
#
# ISO 15.2.18.4.4
def
each
(
&
block
)
self
.
class
.
members
.
each
{
|
field
|
block
.
call
(
self
[
field
])
...
...
@@ -10,7 +16,12 @@ class Struct
self
end
# 15.2.18.4.5
##
# Calls the given block for each element of +self+
# and pass the name and value of the respectiev
# element.
#
# ISO 15.2.18.4.5
def
each_pair
(
&
block
)
self
.
class
.
members
.
each
{
|
field
|
block
.
call
(
field
.
to_sym
,
self
[
field
])
...
...
@@ -18,7 +29,12 @@ class Struct
self
end
# 15.2.18.4.7
##
# Calls the given block for each element of +self+
# and returns an array with all elements of which
# block is not false.
#
# ISO 15.2.18.4.7
def
select
(
&
block
)
ary
=
[]
self
.
class
.
members
.
each
{
|
field
|
...
...
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