opal 0.3.2 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. data/README.md +85 -127
  2. data/bin/opal +3 -3
  3. data/lib/core.rb +114 -0
  4. data/{gems/core/lib → lib}/core/array.rb +68 -187
  5. data/{gems/core/lib → lib}/core/basic_object.rb +22 -5
  6. data/lib/core/class.rb +38 -0
  7. data/{gems/core/lib → lib}/core/dir.rb +1 -1
  8. data/lib/core/enumerable.rb +33 -0
  9. data/{gems/core/lib → lib}/core/error.rb +1 -4
  10. data/{gems/core/lib → lib}/core/false_class.rb +0 -0
  11. data/{gems/core/lib → lib}/core/file.rb +11 -3
  12. data/{gems/core/lib → lib}/core/hash.rb +12 -0
  13. data/{gems/core/lib → lib}/core/kernel.rb +114 -86
  14. data/lib/core/match_data.rb +33 -0
  15. data/lib/core/module.rb +97 -0
  16. data/{gems/core/lib → lib}/core/nil_class.rb +0 -0
  17. data/{gems/core/lib → lib}/core/numeric.rb +5 -0
  18. data/{gems/core/lib → lib}/core/object.rb +0 -0
  19. data/{gems/core/lib → lib}/core/proc.rb +13 -3
  20. data/{gems/core/lib → lib}/core/range.rb +10 -0
  21. data/{gems/core/lib → lib}/core/regexp.rb +33 -1
  22. data/{gems/core/lib → lib}/core/string.rb +25 -10
  23. data/{gems/core/lib → lib}/core/symbol.rb +3 -3
  24. data/{gems/core/lib → lib}/core/top_self.rb +0 -0
  25. data/{gems/core/lib → lib}/core/true_class.rb +0 -0
  26. data/lib/dev.rb +169 -0
  27. data/{gems/ospec/lib → lib}/ospec.rb +1 -0
  28. data/lib/ospec/autorun.rb +8 -0
  29. data/{gems/ospec/lib → lib}/ospec/dsl.rb +2 -2
  30. data/{gems/ospec/lib → lib}/ospec/example.rb +0 -0
  31. data/{gems/ospec/lib → lib}/ospec/example/before_and_after_hooks.rb +0 -0
  32. data/{gems/ospec/lib → lib}/ospec/example/errors.rb +0 -0
  33. data/{gems/ospec/lib → lib}/ospec/example/example_group.rb +0 -0
  34. data/{gems/ospec/lib → lib}/ospec/example/example_group_factory.rb +0 -3
  35. data/{gems/ospec/lib → lib}/ospec/example/example_group_hierarchy.rb +4 -3
  36. data/{gems/ospec/lib → lib}/ospec/example/example_group_methods.rb +1 -1
  37. data/{gems/ospec/lib → lib}/ospec/example/example_group_proxy.rb +3 -2
  38. data/{gems/ospec/lib → lib}/ospec/example/example_methods.rb +1 -1
  39. data/{gems/ospec/lib → lib}/ospec/example/example_proxy.rb +7 -7
  40. data/{gems/ospec/lib → lib}/ospec/expectations.rb +0 -0
  41. data/{gems/ospec/lib → lib}/ospec/expectations/errors.rb +0 -0
  42. data/{gems/ospec/lib → lib}/ospec/expectations/fail_with.rb +4 -3
  43. data/{gems/ospec/lib → lib}/ospec/expectations/handler.rb +6 -0
  44. data/lib/ospec/helpers/scratch.rb +18 -0
  45. data/{gems/ospec/lib → lib}/ospec/matchers.rb +2 -2
  46. data/{gems/ospec/lib → lib}/ospec/matchers/be.rb +0 -0
  47. data/{gems/ospec/lib → lib}/ospec/matchers/generated_descriptions.rb +0 -0
  48. data/{gems/ospec/lib → lib}/ospec/matchers/operator_matcher.rb +2 -0
  49. data/lib/ospec/matchers/raise_error.rb +38 -0
  50. data/lib/ospec/runner.rb +90 -0
  51. data/{gems/ospec/lib → lib}/ospec/runner/example_group_runner.rb +10 -13
  52. data/lib/ospec/runner/formatter/html_formatter.rb +139 -0
  53. data/{gems/ospec/lib → lib}/ospec/runner/formatter/terminal_formatter.rb +0 -0
  54. data/{gems/ospec/lib → lib}/ospec/runner/options.rb +1 -3
  55. data/{gems/ospec/lib → lib}/ospec/runner/reporter.rb +0 -9
  56. data/lib/racc/parser.rb +165 -0
  57. data/lib/strscan.rb +52 -0
  58. data/{lib → opal_lib}/opal.rb +2 -0
  59. data/opal_lib/opal/build_methods.rb +51 -0
  60. data/opal_lib/opal/builder.rb +164 -0
  61. data/opal_lib/opal/bundle.rb +70 -0
  62. data/opal_lib/opal/command.rb +68 -0
  63. data/{lib → opal_lib}/opal/context.rb +21 -9
  64. data/{lib → opal_lib}/opal/context/console.rb +0 -2
  65. data/opal_lib/opal/context/file_system.rb +34 -0
  66. data/{lib → opal_lib}/opal/context/loader.rb +26 -8
  67. data/opal_lib/opal/gem.rb +84 -0
  68. data/{lib → opal_lib}/opal/rake/builder_task.rb +2 -2
  69. data/opal_lib/opal/rake/spec_task.rb +32 -0
  70. data/{lib → opal_lib}/opal/ruby/nodes.rb +730 -109
  71. data/{lib → opal_lib}/opal/ruby/parser.rb +90 -23
  72. data/opal_lib/opal/ruby/ruby_parser.rb +4862 -0
  73. data/opal_lib/opal/ruby/ruby_parser.y +1454 -0
  74. data/opal_lib/opal/version.rb +4 -0
  75. data/runtime/class.js +359 -0
  76. data/runtime/debug.js +84 -0
  77. data/runtime/fs.js +199 -0
  78. data/runtime/init.js +558 -0
  79. data/runtime/loader.js +351 -0
  80. data/runtime/module.js +109 -0
  81. data/runtime/post.js +10 -0
  82. data/runtime/pre.js +7 -0
  83. data/runtime/runtime.js +351 -0
  84. metadata +88 -175
  85. data/.gitignore +0 -7
  86. data/Changelog +0 -31
  87. data/LICENSE +0 -75
  88. data/Rakefile +0 -86
  89. data/gems/core/README.md +0 -14
  90. data/gems/core/Rakefile +0 -8
  91. data/gems/core/core.gemspec +0 -13
  92. data/gems/core/lib/core.rb +0 -34
  93. data/gems/core/lib/core/class.rb +0 -31
  94. data/gems/core/lib/core/module.rb +0 -100
  95. data/gems/core/lib/core/vm.rb +0 -16
  96. data/gems/core/spec/core/array/append_spec.rb +0 -30
  97. data/gems/core/spec/core/array/assoc_spec.rb +0 -29
  98. data/gems/core/spec/core/array/at_spec.rb +0 -37
  99. data/gems/core/spec/core/array/clear_spec.rb +0 -22
  100. data/gems/core/spec/core/array/collect_bang_spec.rb +0 -27
  101. data/gems/core/spec/core/array/collect_spec.rb +0 -27
  102. data/gems/core/spec/core/array/compact_spec.rb +0 -41
  103. data/gems/core/spec/core/array/concat_spec.rb +0 -15
  104. data/gems/core/spec/core/array/constructor_spec.rb +0 -14
  105. data/gems/core/spec/core/array/each_spec.rb +0 -9
  106. data/gems/core/spec/core/array/element_reference_spec.rb +0 -4
  107. data/gems/core/spec/core/array/first_spec.rb +0 -35
  108. data/gems/core/spec/core/array/include_spec.rb +0 -9
  109. data/gems/core/spec/core/array/join_spec.rb +0 -6
  110. data/gems/core/spec/core/array/last_spec.rb +0 -51
  111. data/gems/core/spec/core/array/length_spec.rb +0 -6
  112. data/gems/core/spec/core/array/map_spec.rb +0 -33
  113. data/gems/core/spec/core/array/reverse_spec.rb +0 -6
  114. data/gems/core/spec/core/builtin_constants/builtin_constants_spec.rb +0 -7
  115. data/gems/core/spec/core/false/and_spec.rb +0 -10
  116. data/gems/core/spec/core/false/inspect_spec.rb +0 -6
  117. data/gems/core/spec/core/false/or_spec.rb +0 -10
  118. data/gems/core/spec/core/false/to_s_spec.rb +0 -6
  119. data/gems/core/spec/core/false/xor_spec.rb +0 -10
  120. data/gems/core/spec/core/file/join_spec.rb +0 -19
  121. data/gems/core/spec/core/hash/assoc_spec.rb +0 -32
  122. data/gems/core/spec/core/kernel/instance_eval_spec.rb +0 -0
  123. data/gems/core/spec/core/kernel/loop_spec.rb +0 -24
  124. data/gems/core/spec/core/kernel/raise_spec.rb +0 -0
  125. data/gems/core/spec/core/module/attr_accessor_spec.rb +0 -28
  126. data/gems/core/spec/core/number/lt_spec.rb +0 -12
  127. data/gems/core/spec/core/string/sub_spec.rb +0 -24
  128. data/gems/core/spec/core/true/and_spec.rb +0 -10
  129. data/gems/core/spec/core/true/inspect_spec.rb +0 -6
  130. data/gems/core/spec/core/true/or_spec.rb +0 -10
  131. data/gems/core/spec/core/true/to_s_spec.rb +0 -6
  132. data/gems/core/spec/core/true/xor_spec.rb +0 -10
  133. data/gems/core/spec/language/and_spec.rb +0 -61
  134. data/gems/core/spec/language/array_spec.rb +0 -68
  135. data/gems/core/spec/language/block_spec.rb +0 -38
  136. data/gems/core/spec/language/break_spec.rb +0 -36
  137. data/gems/core/spec/language/case_spec.rb +0 -103
  138. data/gems/core/spec/language/def_spec.rb +0 -21
  139. data/gems/core/spec/language/eigenclass_spec.rb +0 -60
  140. data/gems/core/spec/language/file_spec.rb +0 -13
  141. data/gems/core/spec/language/fixtures/block.rb +0 -21
  142. data/gems/core/spec/language/fixtures/super.rb +0 -293
  143. data/gems/core/spec/language/hash_spec.rb +0 -29
  144. data/gems/core/spec/language/if_spec.rb +0 -54
  145. data/gems/core/spec/language/loop_spec.rb +0 -11
  146. data/gems/core/spec/language/metaclass_spec.rb +0 -21
  147. data/gems/core/spec/language/method_spec.rb +0 -124
  148. data/gems/core/spec/language/next_spec.rb +0 -25
  149. data/gems/core/spec/language/or_spec.rb +0 -34
  150. data/gems/core/spec/language/redo_spec.rb +0 -24
  151. data/gems/core/spec/language/regexp_spec.rb +0 -26
  152. data/gems/core/spec/language/rescue_spec.rb +0 -20
  153. data/gems/core/spec/language/return_spec.rb +0 -47
  154. data/gems/core/spec/language/string_spec.rb +0 -25
  155. data/gems/core/spec/language/super_spec.rb +0 -32
  156. data/gems/core/spec/language/until_spec.rb +0 -157
  157. data/gems/core/spec/language/variables_spec.rb +0 -155
  158. data/gems/core/spec/language/while_spec.rb +0 -163
  159. data/gems/core/spec/spec_helper.rb +0 -5
  160. data/gems/core_fs/README.md +0 -19
  161. data/gems/dev/Rakefile +0 -5
  162. data/gems/dev/lib/dev.js +0 -99
  163. data/gems/dev/lib/dev/generator.js +0 -1264
  164. data/gems/dev/lib/dev/parser.js +0 -979
  165. data/gems/dev/lib/dev/ruby_parser.js +0 -1088
  166. data/gems/dev/lib/dev/ruby_parser.y +0 -1267
  167. data/gems/dev/lib/dev/string_scanner.js +0 -38
  168. data/gems/dev/tools/racc2js/README.md +0 -39
  169. data/gems/dev/tools/racc2js/math_parser.js +0 -222
  170. data/gems/dev/tools/racc2js/math_parser.rb +0 -133
  171. data/gems/dev/tools/racc2js/math_parser.y +0 -28
  172. data/gems/dev/tools/racc2js/parser.js +0 -218
  173. data/gems/dev/tools/racc2js/racc2js.rb +0 -153
  174. data/gems/json/README.md +0 -4
  175. data/gems/json/json.gemspec +0 -14
  176. data/gems/json/lib/json.rb +0 -64
  177. data/gems/json/lib/json/ext.rb +0 -51
  178. data/gems/json/lib/json/json2.js +0 -481
  179. data/gems/ospec/README.md +0 -0
  180. data/gems/ospec/lib/ospec/autorun.rb +0 -3
  181. data/gems/ospec/lib/ospec/runner.rb +0 -40
  182. data/gems/ospec/lib/ospec/runner/formatter/html_formatter.rb +0 -91
  183. data/gems/ospec/ospec.gemspec +0 -0
  184. data/gems/rquery/README.md +0 -9
  185. data/gems/rquery/lib/rquery.rb +0 -10
  186. data/gems/rquery/lib/rquery/ajax.rb +0 -4
  187. data/gems/rquery/lib/rquery/css.rb +0 -96
  188. data/gems/rquery/lib/rquery/document.rb +0 -25
  189. data/gems/rquery/lib/rquery/element.rb +0 -292
  190. data/gems/rquery/lib/rquery/event.rb +0 -108
  191. data/gems/rquery/lib/rquery/jquery.js +0 -8177
  192. data/gems/rquery/lib/rquery/request.rb +0 -138
  193. data/gems/rquery/lib/rquery/response.rb +0 -49
  194. data/gems/rquery/rquery.gemspec +0 -16
  195. data/lib/opal.js +0 -1597
  196. data/lib/opal/builder.rb +0 -117
  197. data/lib/opal/bundle.rb +0 -131
  198. data/lib/opal/command.rb +0 -11
  199. data/lib/opal/context/file_system.rb +0 -19
  200. data/lib/opal/gem.rb +0 -153
  201. data/lib/opal/ruby/ruby_parser.rb +0 -5170
  202. data/lib/opal/ruby/ruby_parser.y +0 -1298
  203. data/opal.gemspec +0 -15
@@ -4,7 +4,8 @@
4
4
  # methods are defined on it. It therefore becomes useful for such
5
5
  # applications as HashStructs.
6
6
  class BasicObject
7
- def initialize
7
+
8
+ def initialize(*a)
8
9
  # ...
9
10
  end
10
11
 
@@ -17,13 +18,29 @@ class BasicObject
17
18
  self == other
18
19
  end
19
20
 
20
- def __send__(method_id, *args)
21
- `args.unshift(self);
22
- return self.$m[#{method_id.to_s}].apply(self, args);`
21
+ def !()
22
+ self ? false : true
23
+ end
24
+
25
+ def !=(obj)
26
+ self == obj ? false : true
27
+ end
28
+
29
+ def __send__(method_id, *args, &block)
30
+ `var method = self.$m[#{method_id.to_s}];
31
+
32
+ if ($B.f == arguments.callee) {
33
+ $B.f = method;
34
+ }
35
+
36
+ args.unshift(self);
37
+
38
+ return method.apply(self, args);`
23
39
  end
24
40
 
25
41
  def instance_eval(&block)
26
- `block(self)` if block_given?
42
+ raise ArgumentError, "block not supplied" unless block_given?
43
+ `block(self);`
27
44
  self
28
45
  end
29
46
 
data/lib/core/class.rb ADDED
@@ -0,0 +1,38 @@
1
+ class Class < Module
2
+
3
+ def allocate
4
+ `return new $rb.RObject(self);`
5
+ end
6
+
7
+ def new(*args)
8
+ obj = allocate
9
+
10
+ `if ($B.f == arguments.callee) {
11
+ $B.f = obj.$m.initialize;
12
+ }`
13
+
14
+ obj.initialize *args
15
+ obj
16
+ end
17
+
18
+ def inherited(cls)
19
+ nil
20
+ end
21
+
22
+ def superclass
23
+ `var sup = self.$super;
24
+
25
+ if (!sup) {
26
+ if (self == $rb.BasicObject) return nil;
27
+ throw new Error('RuntimeError: uninitialized class');
28
+ }
29
+
30
+ return sup;`
31
+ end
32
+
33
+ def native_prototype(proto)
34
+ `$rb.native_prototype(self, proto);`
35
+ nil
36
+ end
37
+ end
38
+
@@ -3,7 +3,7 @@ class Dir
3
3
  # OPAL_FS simply points to the main opal.fs namespace. This might be the
4
4
  # default fs in the browser, or may be overriden within the opal build tools
5
5
  # when running on top of the gem runtime. Both are compatible interfaces.
6
- `var OPAL_FS = VM.opal.fs;`
6
+ `var OPAL_FS = $rb.opal.fs;`
7
7
 
8
8
  # Returns a string that is the current working directory for this process.
9
9
  #
@@ -0,0 +1,33 @@
1
+ # The {Enumerable} module.
2
+ module Enumerable
3
+
4
+ # Returns an array containing the items in the receiver.
5
+ #
6
+ # @example
7
+ #
8
+ # (1..4).to_a # => [1, 2, 3, 4]
9
+ # [1, 2, 3].to_a # => [1, 2, 3]
10
+ #
11
+ # @return [Array]
12
+ def to_a
13
+ ary = []
14
+ each { |arg| `ary.push(arg);` }
15
+ ary
16
+ end
17
+
18
+ alias_method :entries, :to_a
19
+
20
+ def collect(&block)
21
+ raise "Enumerable#collect no block given" unless block_given?
22
+ `var result = [];`
23
+
24
+ each do |*args|
25
+ `result.push(#{block.call *args});`
26
+ end
27
+
28
+ `return result;`
29
+ end
30
+
31
+ alias_method :map, :collect
32
+ end
33
+
@@ -33,8 +33,6 @@
33
33
  # platform to platform basis.
34
34
  class Exception
35
35
 
36
- # We also need to set err.$m to the right method table incase a subclass adds
37
- # custom methods.. just get this from the klass: self.
38
36
  def self.allocate
39
37
  `var err = new Error();
40
38
  err.$klass = self;
@@ -44,11 +42,10 @@ class Exception
44
42
 
45
43
  def initialize(message = '')
46
44
  @message = message
47
- `return self.message = self.$klass.__classid__ + ': ' + message;`
48
45
  end
49
46
 
50
47
  def message
51
- @message
48
+ @message || `self.message`
52
49
  end
53
50
 
54
51
  def inspect
File without changes
@@ -1,7 +1,7 @@
1
1
 
2
2
  class File
3
3
  # Use either the browser fs namespace or overriden gem interface.
4
- `var OPAL_FS = VM.opal.fs;`
4
+ `var OPAL_FS = $rb.opal.fs;`
5
5
 
6
6
  # Converts the given `file_name` into its absolute path. The current working
7
7
  # directory is used as the reference unless the `dir_string` is given, in
@@ -10,8 +10,12 @@ class File
10
10
  # @param [String] file_name
11
11
  # @param [String] dir_string
12
12
  # @return [String]
13
- def self.expand_path(file_name, dir_string)
14
- `return OPAL_FS.expand_path(file_name, dir_string);`
13
+ def self.expand_path(file_name, dir_string = nil)
14
+ if dir_string
15
+ `return OPAL_FS.expand_path(file_name, dir_string);`
16
+ else
17
+ `return OPAL_FS.expand_path(file_name);`
18
+ end
15
19
  end
16
20
 
17
21
  # Returns a new string constructed by joining the given args with the default
@@ -50,5 +54,9 @@ class File
50
54
  def self.basename(file_name, suffix)
51
55
  `return OPAL_FS.basename(file_name, suffix);`
52
56
  end
57
+
58
+ def self.exist?(path)
59
+ `return OPAL_FS.exist_p(path) ? Qtrue : Qfalse;`
60
+ end
53
61
  end
54
62
 
@@ -38,6 +38,18 @@
38
38
  # When `Enumerable` gets implemented, the relevant methods will be moved
39
39
  # back into that module.
40
40
  class Hash
41
+
42
+ # Creates a new hash populated with the given objects.
43
+ #
44
+ # @return [Hash]
45
+ def self.[](*args)
46
+ `return $rb.H.apply(null, args);`
47
+ end
48
+
49
+ def self.allocate
50
+ `return $rb.H();`
51
+ end
52
+
41
53
  # Returns a new array populated with the values from `self`.
42
54
  #
43
55
  # @example
@@ -2,87 +2,7 @@
2
2
  # lot of the core object functionality. It is not, however, included in
3
3
  # {BasicObject}.
4
4
  module Kernel
5
- # Repeatedly executes the given block.
6
- #
7
- # @example
8
- #
9
- # loop do
10
- # puts "this will infinetly repeat"
11
- # end
12
- #
13
- # @return [Object] returns the receiver.
14
- def loop
15
- `while (true) {
16
- try {
17
- #{yield};
18
- } catch (e) {
19
- switch (e.$keyword) {
20
- case 2:
21
- return e['@exit_value'];
22
- default:
23
- throw e;
24
- }
25
- }
26
- }
27
-
28
- return self;`
29
- end
30
-
31
- # Simple equivalent to `Proc.new`. Returns a new proc from the given block.
32
- #
33
- # @example
34
- #
35
- # proc { puts "a" }
36
- # # => #<Proc 02002>
37
- #
38
- # @return [Proc]
39
- def proc(&block)
40
- raise ArgumentError, "block required" unless block_given?
41
- block
42
- end
43
-
44
- def lambda(&block)
45
- raise ArgumentError, "block required" unless block_given?
46
- block
47
- end
48
-
49
- # Raises an exception. If given a string, this method will raise a
50
- # RuntimeError with the given string as a message. Otherwise, if the first
51
- # parameter is a subclass of Exception, then the method will raise a new
52
- # instance of the given exception class with the string as a message, if it
53
- # exists, or a fdefault message otherwise.
54
- #
55
- # @example String message
56
- #
57
- # raise "some error"
58
- # # => RuntimeError: some error
59
- #
60
- # @example Exception subclass
61
- #
62
- # raise StandardError, "something went wrong"
63
- # # => StandardError: something went wrong
64
- #
65
- # @param [Exception, String] exception
66
- # @param [String]
67
- # @return [nil]
68
- def raise(exception, string = nil)
69
- `var msg = nil, exc;
70
5
 
71
- if (typeof exception == 'string') {
72
- msg = exception;
73
- exc = #{RuntimeError.new `msg`};
74
- } else if (#{`exception`.kind_of? Exception}.$r) {
75
- exc = exception;
76
- } else {
77
- if (string != nil) msg = string;
78
- exc = #{`exception`.new `msg`};
79
- }
80
- VM.raise(exc);`
81
- end
82
-
83
- def fail(exception, string = nil)
84
- raise exception, string
85
- end
86
6
 
87
7
  def instance_variable_defined?(name)
88
8
  `name = #{name.to_s};
@@ -110,6 +30,11 @@ module Kernel
110
30
  false
111
31
  end
112
32
 
33
+ # raw object flags (used by runtime)
34
+ def __flags__
35
+ `return self.$flags;`
36
+ end
37
+
113
38
  def to_a
114
39
  [self]
115
40
  end
@@ -157,7 +82,7 @@ module Kernel
157
82
  # @param [String, Symbol] method_id
158
83
  # @return [Boolean]
159
84
  def respond_to?(method_id)
160
- `var method = self.$m[#{`method_id`.to_s}];
85
+ `var method = self['m$' + #{`method_id`.to_s}];
161
86
 
162
87
  if (method && !method.$rbMM) {
163
88
  return Qtrue;
@@ -170,12 +95,28 @@ module Kernel
170
95
  self == other
171
96
  end
172
97
 
173
- def send(method_id, *args)
174
- __send__ method_id, *args
98
+ def send(method_id, *args, &block)
99
+ `var method = self.$m[#{method_id.to_s}];
100
+
101
+ if ($B.f == arguments.callee) {
102
+ $B.f = method;
103
+ }
104
+
105
+ args.unshift(self);
106
+
107
+ return method.apply(self, args);`
175
108
  end
176
109
 
177
110
  def class
178
- `return VM.class_real(self.$klass);`
111
+ `return $rb.class_real(self.$klass);`
112
+ end
113
+
114
+ def singleton_class
115
+ `return $rb.singleton_class(self);`
116
+ end
117
+
118
+ def methods
119
+ `return self.$klass.$methods;`
179
120
  end
180
121
 
181
122
  # Returns a random number. If max is `nil`, then the result is 0. Otherwise
@@ -211,7 +152,7 @@ module Kernel
211
152
  #
212
153
  # FIXME: proper hex output needed
213
154
  def to_s
214
- "#<#{`VM.class_real(self.$klass)`}:0x#{`(self.$hash() * 400487).toString(16)`}>"
155
+ "#<#{`$rb.class_real(self.$klass)`}:0x#{`(self.$hash() * 400487).toString(16)`}>"
215
156
  end
216
157
 
217
158
  def inspect
@@ -219,11 +160,98 @@ module Kernel
219
160
  end
220
161
 
221
162
  def const_set(name, value)
222
- `return rb_const_set(VM.class_real(self.$klass), name, value);`
163
+ `return rb_const_set($rb.class_real(self.$klass), name, value);`
223
164
  end
224
165
 
225
166
  def const_defined?(name)
226
167
  false
227
168
  end
169
+
170
+ def =~(obj)
171
+ nil
172
+ end
173
+
174
+ def extend(mod)
175
+ `$rb.extend_module($rb.singleton_class(self), mod);`
176
+ nil
177
+ end
178
+
179
+ # @group Private methods
180
+ private
181
+
182
+ # Raises an exception. If given a string, this method will raise a
183
+ # RuntimeError with the given string as a message. Otherwise, if the first
184
+ # parameter is a subclass of Exception, then the method will raise a new
185
+ # instance of the given exception class with the string as a message, if it
186
+ # exists, or a fdefault message otherwise.
187
+ #
188
+ # @example String message
189
+ #
190
+ # raise "some error"
191
+ # # => RuntimeError: some error
192
+ #
193
+ # @example Exception subclass
194
+ #
195
+ # raise StandardError, "something went wrong"
196
+ # # => StandardError: something went wrong
197
+ #
198
+ # @param [Exception, String] exception
199
+ # @param [String]
200
+ # @return [nil]
201
+ def raise(exception, string = nil)
202
+ `var msg = nil, exc;
203
+
204
+ if (typeof exception == 'string') {
205
+ msg = exception;
206
+ exc = #{RuntimeError.new `msg`};
207
+ } else if (#{`exception`.kind_of? Exception}.$r) {
208
+ exc = exception;
209
+ } else {
210
+ if (string != nil) msg = string;
211
+ exc = #{`exception`.new `msg`};
212
+ }
213
+ $rb.raise_exc(exc);`
214
+ end
215
+
216
+ alias_method :fail, :raise
217
+
218
+ # Repeatedly executes the given block.
219
+ #
220
+ # @example
221
+ #
222
+ # loop do
223
+ # puts "this will infinetly repeat"
224
+ # end
225
+ #
226
+ # @return [Object] returns the receiver.
227
+ def loop
228
+ `while (true) {
229
+ #{yield};
230
+ }
231
+
232
+ return self;`
233
+ end
234
+
235
+ # Simple equivalent to `Proc.new`. Returns a new proc from the given block.
236
+ #
237
+ # @example
238
+ #
239
+ # proc { puts "a" }
240
+ # # => #<Proc 02002>
241
+ #
242
+ # @return [Proc]
243
+ def proc(&block)
244
+ raise ArgumentError,
245
+ "tried to create Proc object without a block" unless block_given?
246
+ block
247
+ end
248
+
249
+ def lambda(&block)
250
+ raise ArgumentError,
251
+ "tried to create Proc object without a block" unless block_given?
252
+ `return $rb.lambda(block);`
253
+ end
254
+
255
+ # @endgroup
228
256
  end
229
257