本文整理汇总了C#中IronRuby.Builtins.Proc类的典型用法代码示例。如果您正苦于以下问题:C# Proc类的具体用法?C# Proc怎么用?C# Proc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Proc类属于IronRuby.Builtins命名空间,在下文中一共展示了Proc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RubyLambdaMethodInfo
internal RubyLambdaMethodInfo(Proc/*!*/ block, string/*!*/ definitionName, RubyMemberFlags flags, RubyModule/*!*/ declaringModule)
: base(flags, declaringModule) {
Assert.NotNull(block, definitionName, declaringModule);
_lambda = block.ToLambda(this);
_definitionName = definitionName;
_id = Interlocked.Increment(ref _Id);
}
示例2: RubyImportDefinition
public RubyImportDefinition(string contractName, Proc mutator)
: base(contractName, null, null, ImportCardinality.ZeroOrOne, false, true, System.ComponentModel.Composition.CreationPolicy.Any)
{
if (mutator == null)
throw new ArgumentNullException("mutator");
_mutator = mutator;
}
示例3: Subclass
// called by Proc#new rule when creating a Ruby subclass of Proc:
public Subclass(RubyClass/*!*/ rubyClass, Proc/*!*/ proc)
: base(proc)
{
Assert.NotNull(rubyClass);
Debug.Assert(!rubyClass.IsSingletonClass);
ImmediateClass = rubyClass;
}
示例4: MethodRetry
public static object MethodRetry(RubyScope/*!*/ scope, Proc proc) {
if (proc != null) {
return RetrySingleton;
} else {
throw new LocalJumpError("retry used out of rescue", scope.FlowControlScope);
}
}
示例5: OverloadResolution_Block1
public void OverloadResolution_Block1() {
var scope = Context.EmptyScope;
var proc = new Proc(ProcKind.Proc, null, scope, new BlockDispatcher0(BlockSignatureAttributes.None, null, 0).
SetMethod(new BlockCallTarget0((x, y) => null)));
var arguments = new[] {
// 1.times
new CallArguments(Context, MO(scope), new[] { MO(1) }, RubyCallSignature.WithScope(0)),
// 1.times &nil
new CallArguments(Context, MO(scope), new[] { MO(1), MO(null) }, RubyCallSignature.WithScopeAndBlock(0)),
// 1.times &p
new CallArguments(Context, MO(1), new[] { MO(proc) }, RubyCallSignature.WithBlock(0)),
// obj.times &p
new CallArguments(Context, MO("foo"), new[] { MO(proc) }, RubyCallSignature.WithBlock(0)),
};
var results = new[] {
"Times2",
"Times1",
"Times3",
"Times4",
};
var metaBuilder = new MetaObjectBuilder(null);
for (int i = 0; i < arguments.Length; i++) {
RubyOverloadResolver resolver;
var bindingTarget = RubyMethodGroupInfo.ResolveOverload(
metaBuilder, arguments[i], "times", GetStaticMethods(typeof(OverloadsWithBlock), "Times*"), SelfCallConvention.SelfIsParameter,
false, out resolver
);
Assert(bindingTarget.Success);
Assert(bindingTarget.Method.Name == results[i]);
}
}
示例6: Each
private static object Each(RubyContext/*!*/ context, object self, Proc/*!*/ block) {
if (self is Enumerator) {
return ((Enumerator)self).Each(context, block);
} else {
return RubySites.Each(context, self, block);
}
}
示例7: MethodRetry
public static object MethodRetry(RuntimeFlowControl/*!*/ rfc, Proc proc) {
if (proc != null) {
return RetrySingleton;
} else {
throw new LocalJumpError("retry used out of rescue", rfc);
}
}
示例8: Each
private static object Each(CallSiteStorage<EachSite>/*!*/ each, RubyContext/*!*/ context, object self, Proc/*!*/ block) {
var enumerator = self as Enumerator;
if (enumerator != null) {
return enumerator.Each(context, block);
} else {
var site = each.GetCallSite("each", RubyCallSignature.WithBlock(0));
return site.Target(site, context, self, block);
}
}
示例9: RubyPart
public RubyPart(RubyPartDefinition definition, Proc createInstance)
{
if (definition == null)
throw new ArgumentNullException("definition");
if (createInstance == null)
throw new ArgumentNullException("createInstance");
_definition = definition;
_instance = new DelayedInit<object>(() => createInstance.Call(createInstance));
}
示例10: MethodRetry
public static object MethodRetry(RubyScope/*!*/ scope, Proc proc) {
if (proc != null) {
return BlockReturnResult.Retry;
} else {
// TODO: can this happen?
// If proc was null then the block argument passed to the call-with-block that returned RetrySingleton would be null and thus
// the call cannot yield to any block that retries.
throw new LocalJumpError("retry used out of rescue", scope.FlowControlScope);
}
}
示例11: CreateRfcForMethod
public static RuntimeFlowControl/*!*/ CreateRfcForMethod(Proc proc) {
RuntimeFlowControl result = new RuntimeFlowControl();
result.IsActiveMethod = true;
if (proc != null && proc.Kind == ProcKind.Block) {
proc.Kind = ProcKind.Proc;
proc.Converter = result;
}
return result;
}
示例12: RubyPartDefinition
public RubyPartDefinition(string displayName, Proc createPart)
{
if (createPart == null)
throw new ArgumentNullException("createPart");
if (displayName == null)
throw new ArgumentNullException("displayName");
_createPart = createPart;
_displayName = displayName;
}
示例13: Trap
public static object Trap(
RubyContext/*!*/ context,
object self,
object signalId,
Proc proc) {
if ((signalId is MutableString) && ((MutableString)signalId).ConvertToString() == "INT") {
context.InterruptSignalHandler = delegate() { proc.Call(); };
} else {
// TODO: For now, just ignore unknown signals. This should be changed to throw an
// exception. We are not doing it yet as it is close to the V1 RTM, and throwing
// an exception might cause some app to misbehave whereas it might have happenned
// to work if no exception is thrown
}
return null;
}
示例14: ToS
public static MutableString/*!*/ ToS(Proc/*!*/ self) {
var context = self.LocalScope.RubyContext;
var str = RubyUtils.ObjectToMutableStringPrefix(context, self);
str.Append('@');
str.Append(self.SourcePath ?? "(unknown)");
str.Append(':');
str.Append(self.SourceLine.ToString());
if (context.RubyOptions.Compatibility >= RubyCompatibility.Ruby19 && self.Kind == ProcKind.Lambda) {
str.Append(" (lambda)");
}
str.Append('>');
return str;
}
示例15: OverloadResolution_Block
public void OverloadResolution_Block() {
var t = GetType();
var gse = new RubyGlobalScope(Context, new Scope(), new object(), true);
var scope = new RubyTopLevelScope(gse, null, new SymbolDictionary());
var proc = new Proc(ProcKind.Proc, null, scope, new BlockDispatcher0((x, y) => null, BlockSignatureAttributes.None));
var scopeArg = new DynamicMetaObject(Ast.Constant(proc.LocalScope), BindingRestrictions.Empty, proc.LocalScope);
var contextArg = new DynamicMetaObject(Ast.Constant(Context), BindingRestrictions.Empty, Context);
var instanceInt = new DynamicMetaObject(Ast.Constant(1), BindingRestrictions.Empty, 1);
var str = "foo";
var instanceStr = new DynamicMetaObject(Ast.Constant(str), BindingRestrictions.Empty, str);
var procArg = new DynamicMetaObject(Ast.Constant(proc), BindingRestrictions.Empty, proc);
var nullArg = new DynamicMetaObject(Ast.Constant(Ast.Constant(null)), BindingRestrictions.Empty, null);
var arguments = new[] {
// 1.times
new CallArguments(scopeArg, instanceInt, new DynamicMetaObject[0], RubyCallSignature.WithScope(0)),
// 1.times &nil
new CallArguments(scopeArg, instanceInt, new[] { nullArg }, RubyCallSignature.WithScopeAndBlock(0)),
// 1.times &p
new CallArguments(contextArg, instanceInt, new[] { procArg }, RubyCallSignature.WithBlock(0)),
// obj.times &p
new CallArguments(contextArg, instanceStr, new[] { procArg }, RubyCallSignature.WithBlock(0)),
};
var results = new[] {
"Times2",
"Times1",
"Times3",
"Times4",
};
for (int i = 0; i < arguments.Length; i++) {
var bindingTarget = RubyMethodGroupInfo.ResolveOverload("times", new[] {
t.GetMethod("Times1"),
t.GetMethod("Times2"),
t.GetMethod("Times3"),
t.GetMethod("Times4"),
}, arguments[i], true, false);
Assert(bindingTarget.Success);
Assert(bindingTarget.Method.Name == results[i]);
}
}