/**
 * Copyright 2005-2007 Yu Zhang
 * Distributed under the GNU General Public License 2.0
 */

package com.xruby.runtime.value;

import java.io.File;

import com.xruby.runtime.lang.RubyBasic;
import com.xruby.runtime.lang.RubyRuntime;

public class RubyDir extends RubyBasic{
    private File dir_;
    
    public RubyDir(String path){
        super(RubyRuntime.DirClass);
        dir_ = new File(path);
    }
    
    public boolean isDirectory(){
        return dir_.isDirectory();
    }
    
}

/**
 * Copyright 2005-2007 Yu Zhang
 * Distributed under the GNU General Public License 2.0
 */

package com.xruby.runtime.value;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.xruby.runtime.lang.RubyBasic;
import com.xruby.runtime.lang.RubyRuntime;

public class RubyDir extends RubyBasic{
    private File dir_;
    private boolean isOpen = true;
    private int curPos;
    private List<String> list = new ArrayList<String>();
    
    public RubyDir(String path){
        super(RubyRuntime.DirClass);
        dir_ = new File(path);
        
        list.add(".");
        list.add("..");
        String[] contents = dir_.list();
        if(contents != null){
            for(int i=0;i<contents.length;i++){
                list.add(contents[i]);
            }
        }
        curPos = 0;
    }
    
    public boolean isDirectory(){
        return dir_.isDirectory();
    }
    
    public void close(){
        isOpen = false;
    }
    
    public boolean isOpen(){
        return isOpen;
    }
    
    public String read(){
        if(curPos >= list.size())
            return null;
        
        String tmp = list.get(curPos);
        curPos++;
        return tmp;
    }
}

add close and read method