Top Constructors Methods
org.jruby.api

public Class Create

extends Object
Class Inheritance
Imports
org.jcodings.Encoding, org.jruby.*, org.jruby.runtime.Block, .ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.util.ByteList, java.util.Collection, .List, java.util.function.BiFunction

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static RubyArray<?>

Returns:

the new array
allocArray
(ThreadContext
the current thread context
context
,
int
to allocate
length
)

Create an empty array with a specific allocated size.

public static RubyArray<?>

Returns:

the new array
allocArray
(ThreadContext
the current thread context
context
,
long
to allocate
length
)

Create an empty array with a specific allocated size.

public static RubyString

Returns:

the new string
dupString
(ThreadContext
the current thread context
context
,
RubyString
the string to be duplicated
string
)

Duplicate the given string and return a String (original subclass of String is not preserved).

public static RubyArray<?>

Returns:

the new array
newArray
(ThreadContext
the current thread context
context
)

Create a new array with the default allocation size

public static RubyArray<?>

Returns:

the new array
newArray
(ThreadContext
the current thread context
context
,
IRubyObject
the lone element in the array
one
)

Create a new array with a single element.

public static RubyArray<?>

Returns:

the new array
newArray
(ThreadContext
the current thread context
context
,
IRubyObject
the lone element in the array
one
,
IRubyObject
the lone element in the array
two
)

Create a new array with two elements.

public static RubyArray<?>

Returns:

the new array
newArray
(ThreadContext
the current thread context
context
,
IRubyObject...
the elements of the array
elements
)

Create a new array with many elements.

public static RubyArray<?>

Returns:

the new array
newArray
(ThreadContext
the current thread context
context
,
IRubyObject
the first element
elt1
,
IRubyObject
the second element
elt2
,
IRubyObject
the third element
elt3
)

Create a new array with three elements.

public static RubyArray<?>

Returns:

a new array
newArray
(ThreadContext
the current thread context
context
,
List<IRubyObject>
the elements of the array
list
)

Create a new array with many elements from a java.util.List.

public static RubyArray<?>

Returns:

the new array
newArray
(ThreadContext
the current thread context
context
,
Collection<? extends IRubyObject>
the elements of the array
elements
)

Create a new array with elements from the given Collection.

public static <T> RubyArray<?>

Returns:

the new array
newArrayFrom
(ThreadContext
the current thread context
context
,
T[]
the elements to transform
elements
,
BiFunction<ThreadContext, T, IRubyObject>
the transformation function
func
)

Create a new Array by applying the given function to the given elements.

public static RubyArray<?>

Returns:

a new array
newArrayNoCopy
(ThreadContext
the current thread context
context
,
IRubyObject...
the elements of the array
elements
)

Create a new array with many elements but do not copy the incoming array of elements.

public static RubyArray<?>

Returns:

the new array
newEmptyArray
(ThreadContext
the current thread context
context
)

Create a new array which is intended to be empty for its entire lifetime.

public static RubyHash

Returns:

a new hash
newEmptyHash
(ThreadContext
the current thread context
context
)

Create a new empty Hash instance.

public static RubyString

Returns:

the new string
newEmptyString
(ThreadContext
the current thread context
context
)

Create a new String which is intended to be empty for its entire lifetime.

public static RubyString

Returns:

the new string
newEmptyString
(ThreadContext
the current thread context
context
,
Encoding encoding)

Create a new String which is intended to be empty for its entire lifetime with a specific encoding.

public static RubyString

Returns:

the new RubyString
newFrozenString
(ThreadContext
the current thread context
context
,
String
the contents to become a string
string
)

Creates a new frozen RubyString from the provided java String.

public static RubyHash

Returns:

a new hash
newHash
(ThreadContext
the current thread context
context
)

Create a new Hash instance.

public static RubyRational

Returns:

a new Rational
newRational
(ThreadContext
the current thread context
context
,
long
the numerator
num
,
long
the denominator
den
)

Create a new Rational with the given long values for numerator and denominator.

public static RubyString

Returns:

the new RubyString
newSharedString
(ThreadContext
the current thread context
context
,
ByteList
the bytes to become a string
bytes
)

Creates a new RubyString from the provided bytelist but use the supplied encoding if possible.

public static RubyString

Returns:

the new RubyString
newSharedString
(ThreadContext
the current thread context
context
,
ByteList
the bytes to become a string
bytes
,
Encoding
to be used (ignoring encoding of bytelist)
encoding
)

Creates a new RubyString from the provided bytelist but use the supplied encoding if possible.

public static RubyHash

Returns:

a new hash
newSmallHash
(ThreadContext
the current thread context
context
)

Create a new Hash instance.

public static RubyHash

Returns:

a new hash
newSmallHash
(ThreadContext
the current thread context
context
,
IRubyObject
the key
key
,
IRubyObject
the value
value
)

Create a new Hash instance with the given pair, optimized for space.

public static RubyString

Returns:

the new RubyString
newString
(ThreadContext
the current thread context
context
,
byte[]
the bytes to become a string
bytes
)

Creates a new RubyString from the provided bytes.

public static RubyString

Returns:

the new RubyString
newString
(ThreadContext
the current thread context
context
,
byte[]
the bytes to become a string
bytes
,
int
start index in source bytes
start
,
int
the length from start index in source bytes
length
)

Creates a new RubyString from the provided bytes.

public static RubyString

Returns:

the new RubyString
newString
(ThreadContext
the current thread context
context
,
ByteList
the bytes to become a string
bytes
)

Creates a new RubyString from the provided bytelist.

public static RubyString

Returns:

the new RubyString
newString
(ThreadContext
the current thread context
context
,
ByteList
the bytes to become a string
bytes
,
Encoding encoding)

Creates a new RubyString from the provided bytelist but use the supplied encoding if possible.

public static RubyString

Returns:

the new RubyString
newString
(ThreadContext
the current thread context
context
,
String
the contents to become a string
string
,
Encoding encoding)

Creates a new RubyString from the provided java String.

public static RubyString

Returns:

the new RubyString
newString
(ThreadContext
the current thread context
context
,
String
the contents to become a string
string
)

Creates a new RubyString from the provided java String.

public static RubyStruct
newStruct(ThreadContext
the current thread context
context
,
RubyClass structClass, Block block)

Create a new Struct.

public static RubyStruct
newStruct(ThreadContext
the current thread context
context
,
RubyClass structClass, IRubyObject
name of class or first member of struct
arg0
,
Block block)

Create a new Struct.

public static RubyStruct
newStruct(ThreadContext
the current thread context
context
,
RubyClass structClass, IRubyObject
name of class or first member of struct
arg0
,
IRubyObject
a member of struct
arg1
,
Block block)

Create a new Struct.

public static RubyStruct
newStruct(ThreadContext
the current thread context
context
,
RubyClass structClass, IRubyObject
name of class or first member of struct
arg0
,
IRubyObject
a member of struct
arg1
,
IRubyObject
a member of struct
arg2
,
Block block)

Create a new Struct.

public static RubyStruct
newStruct(ThreadContext
the current thread context
context
,
RubyClass
expects either a reference to Struct or a subclass of Struct (Passwd for example)
structClass
,
IRubyObject[]
for thr struct
args
,
Block block)

Create a new Struct (prefer 0-3 arity versions of this function if you know you arity and it is Struct and not a subclass of Struct).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Createback to summary
public Create()

Method Detail

allocArrayback to summary
public static RubyArray<?> allocArray(ThreadContext context, int length)

Create an empty array with a specific allocated size. This should be used to make an array where you think you know how big the array will be and you plan on adding data after its construction. It is ok if you add more than this size (it will resize) or less than this size (it will waste a little more space). The goal is to size in a way where we will not have to arraycopy data when the Array grows.

Parameters
context:ThreadContext

the current thread context

length:int

to allocate

Returns:RubyArray<?>

the new array

allocArrayback to summary
public static RubyArray<?> allocArray(ThreadContext context, long length)

Create an empty array with a specific allocated size. This should be used to make an array where you think you know how big the array will be and you plan on adding data after its construction. It is ok if you add more than this size (it will resize) or less than this size (it will waste a little more space). The goal is to size in a way where we will not have to arraycopy data when the Array grows. This version differs from the int override in that it verifies your long value can fit into an int. It will raise if it cannot.

Parameters
context:ThreadContext

the current thread context

length:long

to allocate

Returns:RubyArray<?>

the new array

dupStringback to summary
public static RubyString dupString(ThreadContext context, RubyString string)

Duplicate the given string and return a String (original subclass of String is not preserved).

Parameters
context:ThreadContext

the current thread context

string:RubyString

the string to be duplicated

Returns:RubyString

the new string

newArrayback to summary
public static RubyArray<?> newArray(ThreadContext context)

Create a new array with the default allocation size

Parameters
context:ThreadContext

the current thread context

Returns:RubyArray<?>

the new array

newArrayback to summary
public static RubyArray<?> newArray(ThreadContext context, IRubyObject one)

Create a new array with a single element.

Parameters
context:ThreadContext

the current thread context

one:IRubyObject

the lone element in the array

Returns:RubyArray<?>

the new array

newArrayback to summary
public static RubyArray<?> newArray(ThreadContext context, IRubyObject one, IRubyObject two)

Create a new array with two elements.

Parameters
context:ThreadContext

the current thread context

one:IRubyObject

the lone element in the array

two:IRubyObject

the lone element in the array

Returns:RubyArray<?>

the new array

newArrayback to summary
public static RubyArray<?> newArray(ThreadContext context, IRubyObject... elements)

Create a new array with many elements.

Parameters
context:ThreadContext

the current thread context

elements:IRubyObject[]

the elements of the array

Returns:RubyArray<?>

the new array

newArrayback to summary
public static RubyArray<?> newArray(ThreadContext context, IRubyObject elt1, IRubyObject elt2, IRubyObject elt3)

Create a new array with three elements.

Parameters
context:ThreadContext

the current thread context

elt1:IRubyObject

the first element

elt2:IRubyObject

the second element

elt3:IRubyObject

the third element

Returns:RubyArray<?>

the new array

newArrayback to summary
public static RubyArray<?> newArray(ThreadContext context, List<IRubyObject> list)

Create a new array with many elements from a java.util.List.

Parameters
context:ThreadContext

the current thread context

list:List<IRubyObject>

the elements of the array

Returns:RubyArray<?>

a new array

newArrayback to summary
public static RubyArray<?> newArray(ThreadContext context, Collection<? extends IRubyObject> elements)

Create a new array with elements from the given Collection.

Parameters
context:ThreadContext

the current thread context

elements:Collection<? extends IRubyObject>

the elements of the array

Returns:RubyArray<?>

the new array

newArrayFromback to summary
public static <T> RubyArray<?> newArrayFrom(ThreadContext context, T[] elements, BiFunction<ThreadContext, T, IRubyObject> func)

Create a new Array by applying the given function to the given elements. The resulting Array will be constructed with a minimum amount of allocation.

Parameters
context:ThreadContext

the current thread context

elements:T[]

the elements to transform

func:BiFunction<ThreadContext, T, IRubyObject>

the transformation function

Returns:RubyArray<?>

the new array

newArrayNoCopyback to summary
public static RubyArray<?> newArrayNoCopy(ThreadContext context, IRubyObject... elements)

Create a new array with many elements but do not copy the incoming array of elements.

Parameters
context:ThreadContext

the current thread context

elements:IRubyObject[]

the elements of the array

Returns:RubyArray<?>

a new array

newEmptyArrayback to summary
public static RubyArray<?> newEmptyArray(ThreadContext context)

Create a new array which is intended to be empty for its entire lifetime. It can still grow but the intention is you think it won't grow (or cannot). If you want a default-size array then use Create#newArray(ThreadContext).

Parameters
context:ThreadContext

the current thread context

Returns:RubyArray<?>

the new array

newEmptyHashback to summary
public static RubyHash newEmptyHash(ThreadContext context)

Create a new empty Hash instance. The expectation is that it will remain empty, so we minimize allocation.

Todo

make this actually avoid allocating buckets by fixing RubyHash support for zero buckets.

Parameters
context:ThreadContext

the current thread context

Returns:RubyHash

a new hash

newEmptyStringback to summary
public static RubyString newEmptyString(ThreadContext context)

Create a new String which is intended to be empty for its entire lifetime. It can still grow but the intention is you think it won't grow (or cannot). If you want a default-size array then use Create#newString(ThreadContext, String).

Parameters
context:ThreadContext

the current thread context

Returns:RubyString

the new string

newEmptyStringback to summary
public static RubyString newEmptyString(ThreadContext context, Encoding encoding)

Create a new String which is intended to be empty for its entire lifetime with a specific encoding. It can still grow but the intention is you think it won't grow (or cannot). If you want a default-size array then use Create#newString(ThreadContext, ByteList).

Parameters
context:ThreadContext

the current thread context

Returns:RubyString

the new string

newFrozenStringback to summary
public static RubyString newFrozenString(ThreadContext context, String string)

Creates a new frozen RubyString from the provided java String.

Parameters
context:ThreadContext

the current thread context

string:String

the contents to become a string

Returns:RubyString

the new RubyString

newHashback to summary
public static RubyHash newHash(ThreadContext context)

Create a new Hash instance.

Parameters
context:ThreadContext

the current thread context

Returns:RubyHash

a new hash

newRationalback to summary
public static RubyRational newRational(ThreadContext context, long num, long den)

Create a new Rational with the given long values for numerator and denominator.

Parameters
context:ThreadContext

the current thread context

num:long

the numerator

den:long

the denominator

Returns:RubyRational

a new Rational

newSharedStringback to summary
public static RubyString newSharedString(ThreadContext context, ByteList bytes)

Creates a new RubyString from the provided bytelist but use the supplied encoding if possible. This bytelist may be from a shared source.

Parameters
context:ThreadContext

the current thread context

bytes:ByteList

the bytes to become a string

Returns:RubyString

the new RubyString

newSharedStringback to summary
public static RubyString newSharedString(ThreadContext context, ByteList bytes, Encoding encoding)

Creates a new RubyString from the provided bytelist but use the supplied encoding if possible. This bytelist may be from a shared source.

Parameters
context:ThreadContext

the current thread context

bytes:ByteList

the bytes to become a string

encoding:Encoding

to be used (ignoring encoding of bytelist)

Returns:RubyString

the new RubyString

newSmallHashback to summary
public static RubyHash newSmallHash(ThreadContext context)

Create a new Hash instance. Use this when you expect very few pairs.

Todo

provide a way to allocate a sized small hash

Parameters
context:ThreadContext

the current thread context

Returns:RubyHash

a new hash

newSmallHashback to summary
public static RubyHash newSmallHash(ThreadContext context, IRubyObject key, IRubyObject value)

Create a new Hash instance with the given pair, optimized for space.

Parameters
context:ThreadContext

the current thread context

key:IRubyObject

the key

value:IRubyObject

the value

Returns:RubyHash

a new hash

newStringback to summary
public static RubyString newString(ThreadContext context, byte[] bytes)

Creates a new RubyString from the provided bytes.

Parameters
context:ThreadContext

the current thread context

bytes:byte[]

the bytes to become a string

Returns:RubyString

the new RubyString

newStringback to summary
public static RubyString newString(ThreadContext context, byte[] bytes, int start, int length)

Creates a new RubyString from the provided bytes.

Parameters
context:ThreadContext

the current thread context

bytes:byte[]

the bytes to become a string

start:int

start index in source bytes

length:int

the length from start index in source bytes

Returns:RubyString

the new RubyString

newStringback to summary
public static RubyString newString(ThreadContext context, ByteList bytes)

Creates a new RubyString from the provided bytelist.

Parameters
context:ThreadContext

the current thread context

bytes:ByteList

the bytes to become a string

Returns:RubyString

the new RubyString

newStringback to summary
public static RubyString newString(ThreadContext context, ByteList bytes, Encoding encoding)

Creates a new RubyString from the provided bytelist but use the supplied encoding if possible.

Parameters
context:ThreadContext

the current thread context

bytes:ByteList

the bytes to become a string

Returns:RubyString

the new RubyString

newStringback to summary
public static RubyString newString(ThreadContext context, String string, Encoding encoding)

Creates a new RubyString from the provided java String.

Parameters
context:ThreadContext

the current thread context

string:String

the contents to become a string

Returns:RubyString

the new RubyString

newStringback to summary
public static RubyString newString(ThreadContext context, String string)

Creates a new RubyString from the provided java String.

Parameters
context:ThreadContext

the current thread context

string:String

the contents to become a string

Returns:RubyString

the new RubyString

newStructback to summary
public static RubyStruct newStruct(ThreadContext context, RubyClass structClass, Block block)

Create a new Struct.

Parameters
context:ThreadContext

the current thread context

newStructback to summary
public static RubyStruct newStruct(ThreadContext context, RubyClass structClass, IRubyObject arg0, Block block)

Create a new Struct.

Parameters
context:ThreadContext

the current thread context

arg0:IRubyObject

name of class or first member of struct

newStructback to summary
public static RubyStruct newStruct(ThreadContext context, RubyClass structClass, IRubyObject arg0, IRubyObject arg1, Block block)

Create a new Struct.

Parameters
context:ThreadContext

the current thread context

arg0:IRubyObject

name of class or first member of struct

arg1:IRubyObject

a member of struct

newStructback to summary
public static RubyStruct newStruct(ThreadContext context, RubyClass structClass, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)

Create a new Struct.

Parameters
context:ThreadContext

the current thread context

arg0:IRubyObject

name of class or first member of struct

arg1:IRubyObject

a member of struct

arg2:IRubyObject

a member of struct

newStructback to summary
public static RubyStruct newStruct(ThreadContext context, RubyClass structClass, IRubyObject[] args, Block block)

Create a new Struct (prefer 0-3 arity versions of this function if you know you arity and it is Struct and not a subclass of Struct).

Parameters
context:ThreadContext

the current thread context

structClass:RubyClass

expects either a reference to Struct or a subclass of Struct (Passwd for example)

args:IRubyObject[]

for thr struct