Skip to content
Permalink
Browse files

Nicer API.

  • Loading branch information
Alex Gaynor
Alex Gaynor committed Mar 19, 2013
1 parent 196b052 commit 3189bf96553b9499d17f227ecb0fa6b4a6ed4bc6
Showing with 7 additions and 5 deletions.
  1. +1 −2 lib-topaz/enumerable.rb
  2. +6 −3 topaz/modules/topaz.py
@@ -1,5 +1,4 @@
module Enumerable

def first(*args)
if args.empty?
self.each { |e| return e }
@@ -105,7 +104,7 @@ def detect(ifnone = nil, &block)
alias find detect

def take(n)
n = Topaz.coerce_int(n)
n = Topaz.convert_type(n, Fixnum, :to_int)
raise ArgumentError.new("attempt to take negative size") if n < 0
result = []
unless n == 0
@@ -3,6 +3,7 @@
from rpython.rlib.rarithmetic import intmask

from topaz.module import Module, ModuleDef
from topaz.objects.classobject import W_ClassObject


class Topaz(Module):
@@ -16,6 +17,8 @@ def method_intmask(self, space, w_int):
bigint = space.bigint_w(w_int)
return space.newint(intmask(bigint.uintmask()))

@moduledef.function("coerce_int")
def method_coerce_int(self, space, w_obj):
return space.convert_type(w_obj, space.w_fixnum, "to_int")
@moduledef.function("convert_type", method="symbol")
def method_coerce_int(self, space, w_obj, w_type, method):
if not isinstance(w_type, W_ClassObject):
raise space.error(space.w_TypeError, "type argument must be a class")
return space.convert_type(w_obj, w_type, method)

0 comments on commit 3189bf9

Please sign in to comment.