PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  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. using System;
  16. using System.Diagnostics;
  17. using System.Runtime.CompilerServices;
  18. using IronRuby.Runtime;
  19. using Microsoft.Scripting.Runtime;
  20. namespace IronRuby.Builtins {
  21. [RubyClass("NilClass", Extends = typeof(DynamicNull))]
  22. public static class NilClassOps {
  23. #region CLR overrides
  24. [RubyMethod("GetType")]
  25. public static Type GetClrType(object self) {
  26. return typeof(DynamicNull);
  27. }
  28. [RubyMethod("ToString")]
  29. public static string ToClrString(object self) {
  30. return "nil";
  31. }
  32. [RubyMethod("GetHashCode")]
  33. public static int GetClrHashCode(object self) {
  34. return 0;
  35. }
  36. #endregion
  37. #region Public Instance Methods
  38. [RubyMethodAttribute("&")]
  39. public static bool And(object self, object obj) {
  40. Debug.Assert(self == null);
  41. return false;
  42. }
  43. [RubyMethodAttribute("^")]
  44. public static bool Xor(object self, object obj) {
  45. Debug.Assert(self == null);
  46. return obj != null;
  47. }
  48. [RubyMethodAttribute("^")]
  49. public static bool Xor(object self, bool obj) {
  50. Debug.Assert(self == null);
  51. return obj;
  52. }
  53. [RubyMethodAttribute("|")]
  54. public static bool Or(object self, object obj) {
  55. Debug.Assert(self == null);
  56. return obj != null;
  57. }
  58. [RubyMethodAttribute("|")]
  59. public static bool Or(object self, bool obj) {
  60. Debug.Assert(self == null);
  61. return obj;
  62. }
  63. [RubyMethodAttribute("nil?")]
  64. public static bool IsNil(object self) {
  65. Debug.Assert(self == null);
  66. return true;
  67. }
  68. [RubyMethodAttribute("to_a")]
  69. public static RubyArray/*!*/ ToArray(object self) {
  70. Debug.Assert(self == null);
  71. return new RubyArray();
  72. }
  73. [RubyMethodAttribute("to_f")]
  74. public static double ToDouble(object self) {
  75. Debug.Assert(self == null);
  76. return 0.0;
  77. }
  78. [RubyMethodAttribute("to_i")]
  79. public static int ToInteger(object self) {
  80. Debug.Assert(self == null);
  81. return 0;
  82. }
  83. [RubyMethodAttribute("inspect")]
  84. public static MutableString Inspect(object self) {
  85. return MutableString.CreateAscii("nil");
  86. }
  87. [RubyMethodAttribute("to_s")]
  88. public static MutableString/*!*/ ToString(object self) {
  89. Debug.Assert(self == null);
  90. return MutableString.CreateEmpty();
  91. }
  92. [SpecialName]
  93. public static bool op_Implicit(DynamicNull self) {
  94. Debug.Assert(self == null);
  95. return false;
  96. }
  97. #endregion
  98. }
  99. }