Skip to content
Permalink
Browse files

Merge pull request #713 from kostya/hash_default_proc

Hash#default_proc=
  • Loading branch information
alex committed May 19, 2013
2 parents 1ca033c + 92255f2 commit 6b7a65992cd4fb301cf379cee4f7633759952cd8
Showing with 12 additions and 6 deletions.
  1. +0 −6 spec/tags/core/hash/default_proc_tags.txt
  2. +12 −0 topaz/objects/hashobject.py

This file was deleted.

@@ -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):
@@ -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:

0 comments on commit 6b7a659

Please sign in to comment.
You can’t perform that action at this time.