Exemplo n.º 1
0
 public RubySymbol /*!*/ GetSymbol(RubyContext /*!*/ context)
 {
     return(_symbol ?? (_symbol = context.EncodeIdentifier(_string)));
 }
Exemplo n.º 2
0
 public static MutableString /*!*/ ToString(RubySymbol /*!*/ self)
 {
     return(self.String.Clone());
 }
Exemplo n.º 3
0
 public static RubyEncoding GetCompatible(RubyClass /*!*/ self, [NotNull] RubyEncoding /*!*/ encoding, [NotNull] RubySymbol /*!*/ symbol)
 {
     return(GetCompatible(self, encoding, symbol.String));
 }
Exemplo n.º 4
0
 public static object Match(BinaryOpStorageWithScope /*!*/ storage, RubyScope /*!*/ scope, RubySymbol /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ pattern)
 {
     return(MutableStringOps.Match(storage, scope, self.String.Clone(), pattern));
 }
Exemplo n.º 5
0
 public static RubyEncoding /*!*/ GetEncoding(RubySymbol /*!*/ self)
 {
     return(self.Encoding);
 }
Exemplo n.º 6
0
 public static bool Equals(RubySymbol /*!*/ self, object other)
 {
     return(false);
 }
Exemplo n.º 7
0
 public static object Match(BinaryOpStorageWithScope /*!*/ storage, RubyScope /*!*/ scope, RubySymbol /*!*/ self, object obj)
 {
     return(MutableStringOps.Match(storage, scope, self.String.Clone(), obj));
 }
Exemplo n.º 8
0
 internal bool HasKey(RubySymbol /*!*/ key)
 {
     lock (_threadLocalStorage) {
         return(_threadLocalStorage.ContainsKey(key));
     }
 }
Exemplo n.º 9
0
        public static object GetElement(Thread /*!*/ self, [NotNull] RubySymbol /*!*/ key)
        {
            RubyThreadInfo info = RubyThreadInfo.FromThread(self);

            return(info[key]);
        }
Exemplo n.º 10
0
 public static int ToInteger(RubySymbol /*!*/ self)
 {
     return(self.Id);
 }
Exemplo n.º 11
0
 public static object Match(RubyScope /*!*/ scope, RubySymbol /*!*/ self, [NotNull] RubyRegex /*!*/ regex)
 {
     return(MutableStringOps.Match(scope, self.ToMutableString(), regex));
 }
Exemplo n.º 12
0
 public static object NewAnonymousStruct(BlockParam block, RubyClass /*!*/ self, [NotNull] RubySymbol /*!*/ firstAttibuteName,
                                         [DefaultProtocol, NotNullItems] params string /*!*/[] /*!*/ attributeNames)
 {
     return(CreateAnonymousWithFirstAttribute(block, self, RubyOps.ConvertSymbolToClrString(firstAttibuteName), attributeNames));
 }
Exemplo n.º 13
0
 public static object SetValue(RubyStruct /*!*/ self, [NotNull] RubySymbol /*!*/ name, object value)
 {
     return(self[name.ToString()] = value);
 }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
 public static bool Equals(RubySymbol /*!*/ lhs, [NotNull] RubySymbol /*!*/ rhs)
 {
     return(lhs.Equals(rhs));
 }
Exemplo n.º 16
0
        public static object HasKey(Thread /*!*/ self, [NotNull] RubySymbol /*!*/ key)
        {
            RubyThreadInfo info = RubyThreadInfo.FromThread(self);

            return(info.HasKey(key));
        }
Exemplo n.º 17
0
 public static bool Equals(RubyContext /*!*/ context, RubySymbol /*!*/ lhs, [NotNull] ClrName /*!*/ rhs)
 {
     return(ClrNameOps.IsEqual(context, rhs, lhs));
 }
Exemplo n.º 18
0
 public static RubySymbol /*!*/ ToSymbol(RubySymbol /*!*/ self)
 {
     return(self);
 }
Exemplo n.º 19
0
 public static object Match(ClrName /*!*/ self, [NotNull] RubySymbol /*!*/ str)
 {
     throw RubyExceptions.CreateTypeError("type mismatch: Symbol given");
 }
Exemplo n.º 20
0
 public static string /*!*/ ToClrString(RubySymbol /*!*/ self)
 {
     return(self.ToString());
 }
Exemplo n.º 21
0
 public static object Match(BinaryOpStorageWithScope /*!*/ storage, RubyScope /*!*/ scope, RubySymbol /*!*/ self, [NotNull] RubyRegex /*!*/ regex)
 {
     return(MutableStringOps.Match(storage, scope, self.String.Clone(), regex));
 }
Exemplo n.º 22
0
 public static Proc /*!*/ ToProc(RubyScope /*!*/ scope, RubySymbol /*!*/ self)
 {
     return(Proc.CreateMethodInvoker(scope, self.ToString()));
 }
Exemplo n.º 23
0
 public static bool IsEmpty(RubySymbol /*!*/ self)
 {
     return(self.IsEmpty);
 }
Exemplo n.º 24
0
 public static int Compare(RubySymbol /*!*/ self, [NotNull] RubySymbol /*!*/ other)
 {
     return(Math.Sign(self.CompareTo(other)));
 }
Exemplo n.º 25
0
 public static int GetLength(RubySymbol /*!*/ self)
 {
     return((self.Encoding.IsKCoding) ? self.GetByteCount() : self.GetCharCount());
 }
Exemplo n.º 26
0
 public static int Compare(RubyContext /*!*/ context, RubySymbol /*!*/ self, [NotNull] ClrName /*!*/ other)
 {
     return(-ClrNameOps.Compare(context, other, self));
 }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
 public static object Compare(RubySymbol /*!*/ self, object other)
 {
     return(null);
 }
Exemplo n.º 29
0
 public static RubyEncoding GetCompatible(RubyClass /*!*/ self, [NotNull] RubySymbol /*!*/ symbol, [NotNull] MutableString /*!*/ str)
 {
     return(GetCompatible(self, symbol.String, str));
 }
Exemplo n.º 30
0
 public Symbol(string str, RubySymbol sym)
 {
     _string = str;
     _symbol = sym;
 }