Module: Kernel
- Defined in:
- opal/stdlib/minitest/spec.rb,
opal/stdlib/pp.rb,
opal/stdlib/native.rb,
opal/stdlib/pathname.rb,
opal/stdlib/phantomjs.rb,
opal/stdlib/opal-parser.rb,
opal/stdlib/nodejs/process.rb,
opal/stdlib/nodejs/require.rb,
opal/stdlib/nodejs/runtime.rb
Overview
:nodoc:
Instance Method Summary collapse
- #__prepare_require__(path) ⇒ Object
- #Array(object, *args, &block) ⇒ Object
- #caller ⇒ Object
- #eval(str) ⇒ Object
- #exit(status = true) ⇒ Object
- #load(path) ⇒ Object
- #Native(obj) ⇒ Object
- #native?(value) ⇒ Boolean
- #node_require(name) ⇒ Object
- #Pathname(path) ⇒ Object
- #pretty_inspect ⇒ Object
- #require(path) ⇒ Object
- #require_remote(url) ⇒ Object
Instance Method Details
#__prepare_require__(path) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'opal/stdlib/nodejs/require.rb', line 4 def __prepare_require__(path) name = `Opal.normalize_loadable_path(#{path})` full_path = name.end_with?('.rb') ? name : name+'.rb' if `!Opal.modules[#{name}]` ruby = File.read(full_path) compiler = Opal::Compiler.new(ruby, requirable: true, file: name) js = compiler.compile compiler.requires.each do |sub_path| __prepare_require__(sub_path) end `eval(#{js})` end name rescue => e raise [path, name, full_path].inspect+e. end |
#Array(object, *args, &block) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'opal/stdlib/native.rb', line 144 def Array(object, *args, &block) %x{ if (object == null || object === nil) { return []; } else if (#{native?(object)}) { return #{Native::Array.new(object, *args, &block).to_a}; } else if (#{object.respond_to? :to_ary}) { return #{object.to_ary}; } else if (#{object.respond_to? :to_a}) { return #{object.to_a}; } else { return [object]; } } end |
#caller ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'opal/stdlib/nodejs/process.rb', line 7 def caller %x{ var stack; try { var err = Error("my error"); throw err; } catch(e) { stack = e.stack; } return stack.$split("\n").slice(3); } end |
#eval(str) ⇒ Object
6 7 8 9 |
# File 'opal/stdlib/opal-parser.rb', line 6 def eval(str) code = Opal.compile str, file: '(eval)' `eval(#{code})` end |
#exit(status = true) ⇒ Object
2 3 4 |
# File 'opal/stdlib/phantomjs.rb', line 2 def exit status = 0 `callPhantom(['exit', status]);` end |
#load(path) ⇒ Object
27 28 29 |
# File 'opal/stdlib/nodejs/require.rb', line 27 def load path `Opal.load(#{__prepare_require__(path)})` end |
#Native(obj) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'opal/stdlib/native.rb', line 134 def Native(obj) if `#{obj} == null` nil elsif native?(obj) Native::Object.new(obj) else obj end end |
#native?(value) ⇒ Boolean
130 131 132 |
# File 'opal/stdlib/native.rb', line 130 def native?(value) `value == null || !value.$$class` end |
#node_require(name) ⇒ Object
22 23 24 |
# File 'opal/stdlib/nodejs/runtime.rb', line 22 def node_require name `OpalNode.node_require(#{name})` end |
#Pathname(path) ⇒ Object
52 53 54 |
# File 'opal/stdlib/pathname.rb', line 52 def Pathname(path) Pathname.new(path) end |
#pretty_inspect ⇒ Object
2 |
# File 'opal/stdlib/pp.rb', line 2 def pretty_inspect; inspect; end |
#require(path) ⇒ Object
23 24 25 |
# File 'opal/stdlib/nodejs/require.rb', line 23 def require(path) `Opal.require(#{__prepare_require__(path)})` end |
#require_remote(url) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'opal/stdlib/opal-parser.rb', line 11 def require_remote url %x{ var r = new XMLHttpRequest(); r.open("GET", url, false); r.send(''); } eval `r.responseText` end |