Skip to content

Commit

Permalink
Merge pull request #713 from kostya/hash_default_proc
Browse files Browse the repository at this point in the history
Hash#default_proc=
  • Loading branch information
alex committed May 19, 2013
2 parents 1ca033c + 92255f2 commit 6b7a659
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 0 additions & 6 deletions spec/tags/core/hash/default_proc_tags.txt

This file was deleted.

12 changes: 12 additions & 0 deletions topaz/objects/hashobject.py
Expand Up @@ -2,6 +2,7 @@
from topaz.modules.enumerable import Enumerable
from topaz.objects.objectobject import W_Object
from topaz.utils.ordereddict import OrderedDict
from topaz.objects.procobject import W_ProcObject


class W_HashObject(W_Object):
Expand Down Expand Up @@ -50,6 +51,17 @@ def method_default_proc(self, space):
return space.w_nil
return self.default_proc

@classdef.method("default_proc=")
def method_set_default_proc(self, space, w_proc):
w_new_proc = space.convert_type(w_proc, space.w_proc, "to_proc")
assert isinstance(w_new_proc, W_ProcObject)
arity = space.int_w(space.send(w_new_proc, "arity"))
if arity != 2 and space.is_true(space.send(w_new_proc, "lambda?")):
raise space.error(space.w_TypeError, "default_proc takes two arguments (2 for %s)" % arity)
self.default_proc = w_new_proc
self.w_default = space.w_nil
return w_proc

@classdef.method("[]")
def method_subscript(self, space, w_key):
try:
Expand Down

0 comments on commit 6b7a659

Please sign in to comment.