PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/NilClassOps.cs

#
C# | 120 lines | 85 code | 21 blank | 14 comment | 13 complexity | ef62d04c460f9c618b4149824a168714 MD5 | raw file
  1/* ****************************************************************************
  2 *
  3 * Copyright (c) Microsoft Corporation. 
  4 *
  5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
  6 * copy of the license can be found in the License.html file at the root of this distribution. If 
  7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
  8 * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
  9 * by the terms of the Apache License, Version 2.0.
 10 *
 11 * You must not remove this notice, or any other, from this software.
 12 *
 13 *
 14 * ***************************************************************************/
 15
 16using System;
 17using System.Diagnostics;
 18using System.Runtime.CompilerServices;
 19using IronRuby.Runtime;
 20using Microsoft.Scripting.Runtime;
 21
 22namespace IronRuby.Builtins {
 23
 24    [RubyClass("NilClass", Extends = typeof(DynamicNull))]
 25    public static class NilClassOps {
 26        #region CLR overrides
 27
 28        [RubyMethod("GetType")]
 29        public static Type GetClrType(object self) {
 30            return typeof(DynamicNull);
 31        }
 32
 33        [RubyMethod("ToString")]
 34        public static string ToClrString(object self) {
 35            return "nil";
 36        }
 37
 38        [RubyMethod("GetHashCode")]
 39        public static int GetClrHashCode(object self) {
 40            return 0;
 41        }
 42
 43        #endregion
 44
 45        #region Public Instance Methods
 46
 47        [RubyMethodAttribute("&")]
 48        public static bool And(object self, object obj) {
 49            Debug.Assert(self == null);
 50            return false;
 51        }
 52
 53        [RubyMethodAttribute("^")]
 54        public static bool Xor(object self, object obj) {
 55            Debug.Assert(self == null);
 56            return obj != null;
 57        }
 58
 59        [RubyMethodAttribute("^")]
 60        public static bool Xor(object self, bool obj) {
 61            Debug.Assert(self == null);
 62            return obj;
 63        }
 64
 65        [RubyMethodAttribute("|")]
 66        public static bool Or(object self, object obj) {
 67            Debug.Assert(self == null);
 68            return obj != null;
 69        }
 70
 71        [RubyMethodAttribute("|")]
 72        public static bool Or(object self, bool obj) {
 73            Debug.Assert(self == null);
 74            return obj;
 75        }
 76
 77        [RubyMethodAttribute("nil?")]
 78        public static bool IsNil(object self) {
 79            Debug.Assert(self == null);
 80            return true;
 81        }
 82
 83        [RubyMethodAttribute("to_a")]
 84        public static RubyArray/*!*/ ToArray(object self) {
 85            Debug.Assert(self == null);
 86            return new RubyArray();
 87        }
 88
 89        [RubyMethodAttribute("to_f")]
 90        public static double ToDouble(object self) {
 91            Debug.Assert(self == null);
 92            return 0.0;
 93        }
 94
 95        [RubyMethodAttribute("to_i")]
 96        public static int ToInteger(object self) {
 97            Debug.Assert(self == null);
 98            return 0;
 99        }
100
101        [RubyMethodAttribute("inspect")]
102        public static MutableString Inspect(object self) {
103            return MutableString.CreateAscii("nil");
104        }
105
106        [RubyMethodAttribute("to_s")]
107        public static MutableString/*!*/ ToString(object self) {
108            Debug.Assert(self == null);
109            return MutableString.CreateEmpty();
110        }
111
112        [SpecialName]
113        public static bool op_Implicit(DynamicNull self) {
114            Debug.Assert(self == null);
115            return false;
116        }
117
118        #endregion
119    }
120}