public final class DynamicObject extends Object
The methods plug and propertyMissing are left undocumented. They are being used
by the Golo runtime to dispatch method invocations on dynamic objects.
| Constructor and Description |
|---|
DynamicObject() |
| Modifier and Type | Method and Description |
|---|---|
DynamicObject |
copy() |
DynamicObject |
define(String name,
Object value)
Defines a property.
|
DynamicObject |
fallback(Object value)
Let the user define a fallback behavior.
|
DynamicObject |
freeze()
Freezes a dynamic object, meaning that its properties cannot be added, updated and removed anymore.
|
Object |
get(String name) |
boolean |
hasMethod(String method)
Verify if a method is defined for the dynamic object.
|
MethodHandle |
invoker(String property,
MethodType type)
Gives an invoker method handle for a given property.
|
boolean |
isFrozen()
Tells whether the dynamic object is frozen or not.
|
DynamicObject |
mixin(DynamicObject other)
Mixes all properties from another dynamic object into this one, overwriting existing properties.
|
Set<Map.Entry<String,Object>> |
properties() |
DynamicObject |
undefine(String name)
Removes a property.
|
public DynamicObject define(String name, Object value)
name - the property name.value - the property value.IllegalStateException - if the dynamic object is frozen.public Object get(String name)
name - the property name.public DynamicObject undefine(String name)
name - the property name.public DynamicObject copy()
public DynamicObject mixin(DynamicObject other)
other - the dynamic object to mix the properties from.public DynamicObject freeze()
public boolean isFrozen()
true if frozen, false otherwise.public MethodHandle invoker(String property, MethodType type)
While this method may be useful in itself, it is mostly relevant for the Golo runtime internals so as to allow calling "methods" on dynamic objects, as in:
# obj is some dynamic object...
obj: foo("bar")
println(foo: bar())
obj: define("plop", |this| -> "Plop!")
println(obj: plop())
property - the name of a property.type - the expected invoker type with at least one parameter (the dynamic object as a receiver).public boolean hasMethod(String method)
method - the method name.true if method is defined, false otherwise.public DynamicObject fallback(Object value)
value - the fallback valueCopyright © 2014 Institut National des Sciences Appliquées de Lyon (INSA-Lyon). All Rights Reserved.