Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add Enumerator class #801

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/array.gb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ class Array
end
end

def to_enum
ArrayEnumerator.new(self)
end

# Return a lazy iterator for self.
#
def lazy
Expand Down
2 changes: 1 addition & 1 deletion lib/array_enumerator.gb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Minimail implementation of an array enumerator.
# Minimum implementation of an array enumerator.
#
# Assumes that the Enumerator interface has two methods: #has_next? and #next.
#
Expand Down
12 changes: 11 additions & 1 deletion vm/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,13 @@ var builtinArrayInstanceMethods = []*BuiltinMethodObject{

},
},
{
// @return [Enumerator]
Name: "to_enum",
Fn: func(receiver Object, sourceLine int, t *Thread, args []Object, blockFrame *normalCallFrame) Object {
return t.vm.InitEnumeratorObject(receiver, "", nil)
},
},
{
// Returns the result of interpreting ary as an array of [key value] array pairs.
// Note that the keys should always be String or symbol literals (using symbol literal is preferable).
Expand Down Expand Up @@ -1428,7 +1435,6 @@ var builtinArrayInstanceMethods = []*BuiltinMethodObject{
}

return t.vm.InitHashObject(hash)

},
},
{
Expand Down Expand Up @@ -1817,3 +1823,7 @@ func (a *ArrayObject) unshift(objs []Object) *ArrayObject {
a.Elements = append(objs, a.Elements...)
return a
}

func (a *ArrayObject) Enumerable() bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported method ArrayObject.Enumerable should have comment or be unexported

return true
}
43 changes: 22 additions & 21 deletions vm/classes/classes.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package classes

const (
ObjectClass = "Object"
ClassClass = "Class"
ModuleClass = "Module"
IntegerClass = "Integer"
FloatClass = "Float"
StringClass = "String"
ArrayClass = "Array"
HashClass = "Hash"
BooleanClass = "Boolean"
NullClass = "Null"
ChannelClass = "Channel"
RangeClass = "Range"
MethodClass = "Method"
PluginClass = "Plugin"
GoObjectClass = "GoObject"
FileClass = "File"
RegexpClass = "Regexp"
MatchDataClass = "MatchData"
GoMapClass = "GoMap"
DecimalClass = "Decimal"
BlockClass = "Block"
ObjectClass = "Object"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported const ObjectClass should have comment (or a comment on this block) or be unexported

ClassClass = "Class"
ModuleClass = "Module"
IntegerClass = "Integer"
FloatClass = "Float"
StringClass = "String"
ArrayClass = "Array"
HashClass = "Hash"
BooleanClass = "Boolean"
NullClass = "Null"
ChannelClass = "Channel"
RangeClass = "Range"
MethodClass = "Method"
PluginClass = "Plugin"
GoObjectClass = "GoObject"
FileClass = "File"
RegexpClass = "Regexp"
MatchDataClass = "MatchData"
GoMapClass = "GoMap"
DecimalClass = "Decimal"
BlockClass = "Block"
EnumeratorClass = "Enumerator"
)
Loading