Package org.jruby

Examples of org.jruby.RubyHash$EntryView


        boolean traceEnabled = context.isEventHooksEnabled();
        context.setEventHooksEnabled(false);

        try {
            // dup for JRUBY-6603 (avoid concurrent modification while we walk it)
            RubyHash hash = (RubyHash)runtime.getObject().getConstant("ENV").dup();
            String[] ret, ary;

            if (mergeEnv != null && !mergeEnv.isEmpty()) {
                ret = new String[hash.size() + mergeEnv.size()];
            } else {
                ret = new String[hash.size()];
            }

            int i=0;
            for(Map.Entry e : (Set<Map.Entry>)hash.directEntrySet()) {
                // if the key is nil, raise TypeError
                if (e.getKey() == null) {
                    throw runtime.newTypeError(runtime.getNil(), runtime.getStructClass());
                }
                // ignore if the value is nil
View Full Code Here


        }
        return pathFile;
    }

    private static File findPathExecutable(Ruby runtime, String fname) {
        RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
        IRubyObject pathObject = env.op_aref(runtime.getCurrentContext(), RubyString.newString(runtime, PATH_ENV));
        String[] pathNodes = null;
        if (pathObject == null) {
            pathNodes = DEFAULT_PATH; // ASSUME: not modified by callee
        }
        else {
View Full Code Here

        static ByteOrder getByteOrderOption(ThreadContext context, IRubyObject[] args) {

            ByteOrder order = ByteOrder.nativeOrder();

            if (args.length > 3 && args[3] instanceof RubyHash) {
                RubyHash options = (RubyHash) args[3];
                IRubyObject byte_order = options.fastARef(RubySymbol.newSymbol(context.runtime, "byte_order"));
                if (byte_order instanceof RubySymbol || byte_order instanceof RubyString) {
                    String orderName = byte_order.asJavaString();
                    if ("network".equals(orderName) || "big".equals(orderName)) {
                        order = ByteOrder.BIG_ENDIAN;
                   
View Full Code Here

            return new CodingErrorActions(CodingErrorAction.REPORT,
                    CodingErrorAction.REPORT, null);
        }

        Ruby runtime = context.runtime;
        RubyHash hash = (RubyHash) opts;
        CodingErrorAction onMalformedInput = CodingErrorAction.REPORT;
        CodingErrorAction onUnmappableCharacter = CodingErrorAction.REPORT;
        RubyString replaceWith = null;
           
        IRubyObject replace = hash.fastARef(runtime.newSymbol("replace"));
        if (replace != null && !replace.isNil()) {
            RubyString replaceWithStr = replace.convertToString();
            if (replaceWithStr.size() == 1) { // we can only replaceWith a single char
                replaceWith = replaceWithStr;
            }
        }
           
        IRubyObject invalid = hash.fastARef(runtime.newSymbol("invalid"));
        if (invalid != null && invalid.op_equal(context, runtime.newSymbol("replace")).isTrue()) {
            onMalformedInput = CodingErrorAction.REPLACE;
        }

        IRubyObject undef = hash.fastARef(runtime.newSymbol("undef"));
        if (undef != null && undef.op_equal(context, runtime.newSymbol("replace")).isTrue()) {
            onUnmappableCharacter = CodingErrorAction.REPLACE;
        }
       
        if (replaceWith == null && (onUnmappableCharacter == CodingErrorAction.REPLACE || onMalformedInput == CodingErrorAction.REPLACE)) {
View Full Code Here

        // add all startup load paths to the list first
        addPaths(prependDirectories);

        // add $RUBYLIB paths
        RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
        RubyString env_rubylib = runtime.newString("RUBYLIB");
        if (env.has_key_p(env_rubylib).isTrue()) {
            String rubylib = env.op_aref(runtime.getCurrentContext(), env_rubylib).toString();
            String[] paths = rubylib.split(File.pathSeparator);
            addPaths(paths);
        }

        // wrap in try/catch for security exceptions in an applet
View Full Code Here

    }

    protected LoadServiceResource tryResourceFromHome(SearchState state, String baseName, SuffixType suffixType) throws RaiseException {
        LoadServiceResource foundResource = null;

        RubyHash env = (RubyHash) runtime.getObject().getConstant("ENV");
        RubyString env_home = runtime.newString("HOME");
        if (env.has_key_p(env_home).isFalse()) {
            return null;
        }
        String home = env.op_aref(runtime.getCurrentContext(), env_home).toString();
        String path = baseName.substring(2);

        for (String suffix : suffixType.getSuffixes()) {
            String namePlusSuffix = path + suffix;
            // check home directory; if file exists, retrieve URL and return resource
View Full Code Here

            case ClassIndex.FLOAT:
                write('f');
                RubyFloat.marshalTo((RubyFloat)value, this);
                return;
            case ClassIndex.HASH: {
                RubyHash hash = (RubyHash)value;

                if(hash.getIfNone().isNil()){
                    write('{');
                }else if (hash.hasDefaultProc()) {
                    throw hash.getRuntime().newTypeError("can't dump hash with default proc");
                } else {
                    write('}');
                }

                RubyHash.marshalTo(hash, this);
View Full Code Here

    @Override
    public Object retrieve(ThreadContext context, IRubyObject self, DynamicScope currDynScope,
            Object[] temp) {
        Ruby runtime = context.runtime;
        RubyHash hash = RubyHash.newHash(runtime);

        for (KeyValuePair pair : pairs) {
            IRubyObject key = (IRubyObject) pair.getKey().retrieve(context, self, currDynScope,
                    temp);
            IRubyObject value = (IRubyObject) pair.getValue().retrieve(context, self, currDynScope,
                    temp);

            hash.fastASetCheckString(runtime, key, value);
        }

        return hash;
    }
View Full Code Here

        return createList(listNode);
    }
   
    @Override
    public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        RubyHash hash;

        ListNode list = this.listNode;
        if (list != null) {
            int size = list.size();
View Full Code Here

    }

    protected void assignKwargs(IRubyObject[] args, Ruby runtime, ThreadContext context, DynamicScope scope, IRubyObject self) {
        if (args.length > 0) {
            if (args[args.length - 1] instanceof RubyHash) {
                RubyHash keyValues = (RubyHash)args[args.length - 1];

                if (keywords != null) {
                    for (Node knode : keywords.childNodes()) {
                        KeywordArgNode kwarg = (KeywordArgNode)knode;
                        LocalAsgnNode kasgn = (LocalAsgnNode)kwarg.getAssignable();
                        String name = kasgn.getName();
                        RubySymbol sym = runtime.newSymbol(name);

                        if (keyValues.op_aref(context, sym).isNil()) {
                            kasgn.interpret(runtime, context, self, Block.NULL_BLOCK);
                        } else {
                            IRubyObject value = keyValues.delete(context, sym, Block.NULL_BLOCK);
                            scope.setValue(kasgn.getIndex(), value, kasgn.getDepth());
                        }
                    }
                }

                if (keyRest == null && !keyValues.isEmpty()) {
                    throw runtime.newArgumentError("unknown keyword: " + keyValues.directKeySet().iterator().next());
                }

                if (keyRest != null) {
                    LocalAsgnNode krestAsgn = (LocalAsgnNode)keyRest.getVariable();
                    scope.setValue(krestAsgn.getIndex(), keyValues, krestAsgn.getDepth());
View Full Code Here

TOP

Related Classes of org.jruby.RubyHash$EntryView

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.