Sha256: d89ae37c20d4447c2a9ccdc7d21e2a1cf721324ae46f39da56ebdeed17c5bcfe

Contents?: true

Size: 880 Bytes

Versions: 12

Compression:

Stored size: 880 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?(LibPython::PyObjectStruct)
      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) : LibPython::PyObjectStruct.null
      stop = stop ? Conversions.from_ruby(stop) : LibPython::PyObjectStruct.null
      step = step ? Conversions.from_ruby(step) : LibPython::PyObjectStruct.null
      pyobj = LibPython.PySlice_New(start, stop, step)
      return pyobj.to_ruby unless pyobj.null?
      raise PyError.fetch
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pycall-0.1.0.alpha.20170711 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170502 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170426 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170419b lib/pycall/slice.rb
pycall-0.1.0.alpha.20170419a lib/pycall/slice.rb
pycall-0.1.0.alpha.20170419 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170403 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170329 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170317 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170311 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170309 lib/pycall/slice.rb
pycall-0.1.0.alpha.20170308 lib/pycall/slice.rb