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
162b3625
Commit
162b3625
authored
Jun 21, 2012
by
Daniel Bovensiepen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only open struct class if there is actually already a class
parent
a686ad66
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
37 deletions
+41
-37
mrblib/struct.rb
mrblib/struct.rb
+41
-37
No files found.
mrblib/struct.rb
View file @
162b3625
...
...
@@ -2,45 +2,49 @@
# Struct
#
# ISO 15.2.18
class
Struct
##
# 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
])
}
self
end
if
Object
.
const_defined?
(
:Struct
)
class
Struct
##
# 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
])
}
self
end
##
# 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
])
}
self
end
##
# 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
|
val
=
self
[
field
]
ary
.
push
(
val
)
if
block
.
call
(
val
)
}
ary
##
# 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
])
}
self
end
##
# 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
|
val
=
self
[
field
]
ary
.
push
(
val
)
if
block
.
call
(
val
)
}
ary
end
end
end
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