Skip to content
Permalink
Browse files

Merge pull request #499 from kostya/master

Object#tap
  • Loading branch information
alex committed Mar 12, 2013
2 parents df43188 + 5f0d279 commit 43b86c3de3b3cf76b809696bcd2d0f2b9fa9c429
Showing with 30 additions and 2 deletions.
  1. +1 −0 AUTHORS.rst
  2. +0 −2 spec/tags/core/kernel/tap_tags.txt
  3. +21 −0 tests/objects/test_objectobject.py
  4. +8 −0 topaz/objects/objectobject.py
@@ -18,3 +18,4 @@ Authors
* Armin Rigo
* Robin Schreiber
* Jeremy Thurgood
* Konstantin Makarchev
@@ -1,2 +0,0 @@
fails:Kernel#tap always yields self and returns self
fails:Kernel#tap raises a LocalJumpError when no block given
@@ -389,3 +389,24 @@ class A; def to_str; "to_s"; end; end
return 'aaa'.method(A.new).class
""")
assert self.unwrap(space, w_res) == space.getclassfor(W_MethodObject)

def test_tap(self, space):
with self.raises(space, "LocalJumpError"):
space.execute("1.tap")

with self.raises(space, "LocalJumpError"):
space.execute("'1'.tap")

w_res = space.execute("""
x = nil
1.tap{ |c| x = c }
return x
""")
assert self.unwrap(space, w_res) == 1

w_res = space.execute("""
x = nil
[].tap{ |c| x = c }
return x
""")
assert self.unwrap(space, w_res) == []
@@ -181,6 +181,14 @@ def method_method(self, space, w_sym):
[self]
)

@classdef.method("tap")
def method_tap(self, space, block=None):
if block is not None:
space.invoke_block(block, [self])
else:
raise space.error(space.w_LocalJumpError, "no block given")
return self


class W_Object(W_RootObject):
_attrs_ = ["map", "storage"]

0 comments on commit 43b86c3

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