maybe I am overlooking something but shouldn't the glob already limit the entries to the partitions? In that case it should be sufficient do do

    def self.device_partitions(device)
      Dir.glob(SYSFS_BLOCK_DIRECTORY + device + "/#{device}*").map do |d|
        File.basename(d)
      end
    end