コード例 #1
0
ファイル: ClrStringOps.cs プロジェクト: rudimk/dlr-dotnet
        public static object MethodMissing(RubyScope /*!*/ scope, BlockParam block, string /*!*/ self, [NotNull] RubySymbol /*!*/ name, params object[] /*!*/ args)
        {
            if (name.EndsWith('=') || name.EndsWith('!'))
            {
                throw RubyExceptions.CreateTypeError("Mutating method `{0}' called for an immutable string (System::String)", name);
            }

            // TODO: forward to MutableString until we implement the methods here:
            return(KernelOps.SendMessageOpt(scope, block, ToStr(self), name.ToString(), args));
        }
コード例 #2
0
 public string /*!*/ GetString()
 {
     return(_string ?? (_string = _symbol.ToString()));
 }
コード例 #3
0
ファイル: SymbolOps.cs プロジェクト: sipsorcery/IronRuby
        public static MutableString /*!*/ Inspect(RubyContext /*!*/ context, RubySymbol /*!*/ self)
        {
            var  str = self.ToString();
            bool allowMultiByteCharacters = context.RubyOptions.Compatibility >= RubyCompatibility.Ruby19 || context.KCode != null;

            var result = self.String.Clone();

            // simple cases:
            if (
                Tokenizer.IsMethodName(str, allowMultiByteCharacters) ||
                Tokenizer.IsConstantName(str, allowMultiByteCharacters) ||
                Tokenizer.IsInstanceVariableName(str, allowMultiByteCharacters) ||
                Tokenizer.IsClassVariableName(str, allowMultiByteCharacters) ||
                Tokenizer.IsGlobalVariableName(str, allowMultiByteCharacters)
                )
            {
                result.Insert(0, ':');
            }
            else
            {
                // TODO: this is neither efficient nor complete.
                // Any string that parses as 'sym' should not be quoted.
                switch (str)
                {
                case null:
                    // Ruby doesn't allow empty symbols, we can get one from outside though:
                    return(MutableString.CreateAscii(":\"\""));

                case "!":
                case "|":
                case "^":
                case "&":
                case "<=>":
                case "==":
                case "===":
                case "=~":
                case "!=":
                case "!~":
                case ">":
                case ">=":
                case "<":
                case "<=":
                case "<<":
                case ">>":
                case "+":
                case "-":
                case "*":
                case "/":
                case "%":
                case "**":
                case "~":
                case "+@":
                case "-@":
                case "[]":
                case "[]=":
                case "`":

                case "$!":
                case "$@":
                case "$,":
                case "$;":
                case "$/":
                case "$\\":
                case "$*":
                case "$$":
                case "$?":
                case "$=":
                case "$:":
                case "$\"":
                case "$<":
                case "$>":
                case "$.":
                case "$~":
                case "$&":
                case "$`":
                case "$'":
                case "$+":
                    result.Insert(0, ':');
                    break;

                default:
                    result.Insert(0, ":\"").Append('"');
                    break;
                }
            }

            if (context.RuntimeId != self.RuntimeId)
            {
                result.Append(" @").Append(self.RuntimeId.ToString(CultureInfo.InvariantCulture));
            }

            return(result);
        }
コード例 #4
0
ファイル: SymbolOps.cs プロジェクト: sipsorcery/IronRuby
 public static Proc /*!*/ ToProc(RubyScope /*!*/ scope, RubySymbol /*!*/ self)
 {
     return(Proc.CreateMethodInvoker(scope, self.ToString()));
 }
コード例 #5
0
ファイル: SymbolOps.cs プロジェクト: sipsorcery/IronRuby
 public static string /*!*/ ToClrString(RubySymbol /*!*/ self)
 {
     return(self.ToString());
 }
コード例 #6
0
 public static object SetValue(RubyStruct /*!*/ self, [NotNull] RubySymbol /*!*/ name, object value)
 {
     return(self[name.ToString()] = value);
 }
コード例 #7
0
 public static object MethodMissing(RubyContext /*!*/ context, object /*!*/ self, [NotNull] RubySymbol /*!*/ name, params object[] /*!*/ args)
 {
     throw RubyExceptions.CreateMethodMissing(context, self, name.ToString());
 }