Java Code Examples for org.jruby.RubyArray#add()
The following examples show how to use
org.jruby.RubyArray#add() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PigJrubyLibrary.java From spork with Apache License 2.0 | 5 votes |
/** * A type specific conversion routine. * * @param ruby the Ruby runtime to create objects in * @param object object to convert * @return analogous Ruby type * @throws ExecException object contained an object that could not convert */ public static RubyArray pigToRuby(Ruby ruby, Tuple object) throws ExecException{ RubyArray rubyArray = ruby.newArray(); for (Object o : object.getAll()) rubyArray.add(pigToRuby(ruby, o)); return rubyArray; }
Example 2
Source File: JrubyScriptEngine.java From spork with Apache License 2.0 | 5 votes |
/** * Consults the scripting container, after the script has been evaluated, to * determine what dependencies to ship. * <p> * FIXME: Corner cases like the following: "def foobar; require 'json'; end" * are NOT dealt with using this method */ private HashSet<String> libsToShip() { RubyArray loadedLibs = (RubyArray)rubyEngine.get("$\""); RubyArray loadPaths = (RubyArray)rubyEngine.get("$LOAD_PATH"); // Current directory first loadPaths.add(0, ""); HashSet<String> toShip = new HashSet<String>(); HashSet<Object> shippedLib = new HashSet<Object>(); for (Object loadPath : loadPaths) { for (Object lib : loadedLibs) { if (lib.toString().equals("pigudf.rb")) continue; if (shippedLib.contains(lib)) continue; String possiblePath = (loadPath.toString().isEmpty()?"":loadPath.toString() + File.separator) + lib.toString(); if ((new File(possiblePath)).exists()) { // remove prefix ./ toShip.add(possiblePath.startsWith("./")?possiblePath.substring(2): possiblePath); shippedLib.add(lib); } } } return toShip; }
Example 3
Source File: AbstractProcessorProxy.java From asciidoctorj with Apache License 2.0 | 5 votes |
private static void handleContextsAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) { Ruby rubyRuntime = rubyClass.getRuntime(); if (processor.isAnnotationPresent(Contexts.class)) { Contexts contexts = processor.getAnnotation(Contexts.class); RubyArray contextList = rubyRuntime.newArray(); for (String value : contexts.value()) { contextList.add(rubyRuntime.newSymbol(value.substring(1))); } rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{ rubyRuntime.newSymbol("contexts"), contextList }); } }
Example 4
Source File: AbstractProcessorProxy.java From asciidoctorj with Apache License 2.0 | 5 votes |
private static void handlePositionalAttributesAnnotation(Class<? extends Processor> processor, RubyClass rubyClass) { Ruby rubyRuntime = rubyClass.getRuntime(); if (processor.isAnnotationPresent(PositionalAttributes.class)) { PositionalAttributes positionalAttributes = processor.getAnnotation(PositionalAttributes.class); RubyArray positionalAttrs = RubyArray.newArray(rubyRuntime); for (String positionalAttribute : positionalAttributes.value()) { positionalAttrs.add(positionalAttribute); } rubyClass.callMethod(rubyRuntime.getCurrentContext(), "option", new IRubyObject[]{ rubyRuntime.newSymbol("positional_attrs"), positionalAttrs }); } }
Example 5
Source File: ReaderImpl.java From asciidoctorj with Apache License 2.0 | 5 votes |
static ReaderImpl createReader(Ruby runtime, List<String> lines) { RubyArray rubyLines = runtime.newArray(lines.size()); for (String line : lines) { rubyLines.add(runtime.newString(line)); } RubyClass readerClass = runtime.getModule("Asciidoctor").getClass("Reader"); return new ReaderImpl(readerClass.callMethod("new", rubyLines)); }
Example 6
Source File: BlockImpl.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Override public void setLines(List<String> lines) { RubyArray newLines = getRuntime().newArray(lines.size()); for (String s: lines) { newLines.add(getRuntime().newString(s)); } setRubyProperty("lines", newLines); }
Example 7
Source File: StructuralNodeImpl.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Override public void setSubstitutions(String... substitutions) { RubyArray subs = (RubyArray) getRubyProperty("@subs"); subs.clear(); if (substitutions != null) { for (String substitution : substitutions) { subs.add(RubyUtils.toSymbol(getRuntime(), substitution)); } } }
Example 8
Source File: StructuralNodeImpl.java From asciidoctorj with Apache License 2.0 | 4 votes |
@Override public void addSubstitution(String substitution) { RubyArray subs = (RubyArray) getRubyProperty("@subs"); subs.add(RubyUtils.toSymbol(getRuntime(), substitution)); }
Example 9
Source File: RubyHashUtil.java From asciidoctorj with Apache License 2.0 | 3 votes |
private static IRubyObject toRubyArray(Ruby rubyRuntime, List<Object> values) { RubyArray rubyArray = RubyArray.newArray(rubyRuntime, values.size()); for (Object value : values) { rubyArray.add(toRubyObject(rubyRuntime, value)); } return rubyArray; }