Sha256: 68272abab94638e7bb220bda82267a4dbfe4cab0bb51e19f0094db0838f87eaf

Contents?: true

Size: 812 Bytes

Versions: 5

Compression:

Stored size: 812 Bytes

Contents

module PyCall
  class Slice
    include PyObjectWrapper

    def self.new(*args)
      start, stop, step = nil
      case args.length
      when 1
        stop = args[0]
        return super(stop) if stop.kind_of?(PyObject)
      when 2
        start, stop = args
      when 3
        start, stop, step = args
      else
        much_or_few = args.length > 3 ? 'much' : 'few'
        raise ArgumentError, "too #{much_or_few} arguments (#{args.length} for 1..3)"
      end
      start = start ? Conversions.from_ruby(start) : PyObject.null
      stop = stop ? Conversions.from_ruby(stop) : PyObject.null
      step = step ? Conversions.from_ruby(step) : PyObject.null
      pyobj = LibPython.PySlice_New(start, stop, step)
      return pyobj.to_ruby unless pyobj.null?
      raise PyError.fetch
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pycall-0.1.0.alpha.20170307 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170302 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170226 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170224b lib/pycall/slice.rb
pycall-0.1.0.alpha.20170224 lib/pycall/slice.rb