Skip to content

Commit

Permalink
Make constructor private, add ProcTable::Error, freeze returned struc…
Browse files Browse the repository at this point in the history
…t and add a TypeError check.
  • Loading branch information
Daniel Berger committed Jun 27, 2016
1 parent 8841371 commit 9bd2de0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/darwin/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module Sys
class ProcTable
extend FFI::Library

# Error typically raised if the ProcTable.ps method fails.
class Error < StandardError; end

# There is no constructor
private_class_method :new

private

PROC_ALL_PIDS = 1
Expand Down Expand Up @@ -132,6 +138,8 @@ def self.fields
# p ProcTable.ps(1001)
#
def self.ps(pid = nil)
raise TypeError unless pid.is_a?(Fixnum) if pid

num = proc_listallpids(nil, 0)
ptr = FFI::MemoryPointer.new(:pid_t, num)
num = proc_listallpids(ptr, ptr.size)
Expand Down Expand Up @@ -169,6 +177,8 @@ def self.ps(pid = nil)
end
end

struct.freeze

if block_given?
yield struct
else
Expand Down

0 comments on commit 9bd2de0

Please sign in to comment.