Module: Kernel
- Defined in:
- lib/source/ruby.rb
Overview
The Kernel module contains methods that are mixed in to the window object and are available in any context.
Instance Method Summary collapse
-
#block_given? ⇒ Boolean
FIX: Incomplete.
-
#fail ⇒ Object
FIX: Incomplete.
- #format(string) ⇒ Object
-
#global_variables ⇒ Object
FIX: Incomplete.
-
#lambda(func) ⇒ Object
call-seq: proc { |…| block } -> a_proc lambda { |…| block } -> a_proc.
-
#local_variables ⇒ Object
FIX: Incomplete.
-
#loop(&block) ⇒ Object
call-seq: loop { || block }.
-
#p ⇒ Object
FIX: Incomplete.
-
#print ⇒ Object
FIX: Incomplete.
-
#printf ⇒ Object
FIX: Incomplete.
-
#proc(func) ⇒ Object
call-seq: proc { |…| block } -> a_proc lambda { |…| block } -> a_proc.
-
#putc(int) ⇒ Object
call-seq: putc(int) -> int.
-
#puts(obj) ⇒ Object
call-seq: puts(obj, …) -> nil.
-
#raise ⇒ Object
FIX: Incomplete.
-
#rand(num = 0) ⇒ Object
call-seq: rand(num = 0) -> numeric.
-
#sleep(duration) ⇒ Object
call-seq: sleep() -> integer.
-
#sprintf(string) ⇒ Object
FIX: Incomplete.
-
#srand ⇒ Object
FIX: Incomplete.
-
#x ⇒ Object
:nodoc:.
Instance Method Details
#block_given? ⇒ Boolean
FIX: Incomplete
1278 1279 1280 |
# File 'lib/source/ruby.rb', line 1278 def block_given? `typeof(arguments[0])=='function'` end |
#format(string) ⇒ Object
1286 1287 1288 |
# File 'lib/source/ruby.rb', line 1286 def format(string) `m$sprintf(string)` end |
#global_variables ⇒ Object
FIX: Incomplete
1291 1292 |
# File 'lib/source/ruby.rb', line 1291 def global_variables end |
#lambda(func) ⇒ Object
call-seq:
proc { |...| block } -> a_proc
lambda { |...| block } -> a_proc
Equivalent to Proc.new …
FIX: Incomplete
1301 1302 1303 1304 1305 |
# File 'lib/source/ruby.rb', line 1301 def lambda(func) `result=new(c$Proc)()` `result._block=func` return `result` end |
#local_variables ⇒ Object
FIX: Incomplete
1308 1309 |
# File 'lib/source/ruby.rb', line 1308 def local_variables end |
#loop(&block) ⇒ Object
call-seq:
loop { || block }
Repeatedly executes the block.
1316 1317 1318 1319 1320 |
# File 'lib/source/ruby.rb', line 1316 def loop(&block) `var result=nil` `while(true){#{yield};}` return `result` end |
#proc(func) ⇒ Object
call-seq:
proc { |...| block } -> a_proc
lambda { |...| block } -> a_proc
Equivalent to Proc.new …
FIX: Incomplete
1341 1342 1343 1344 1345 |
# File 'lib/source/ruby.rb', line 1341 def proc(func) `result=new(c$Proc)()` `result._block=func` return `result` end |
#putc(int) ⇒ Object
call-seq:
putc(int) -> int
FIX: Incomplete
1351 1352 |
# File 'lib/source/ruby.rb', line 1351 def putc(int) end |
#puts(obj) ⇒ Object
call-seq:
puts(obj, ...) -> nil
FIX: Incomplete
1358 1359 1360 1361 1362 |
# File 'lib/source/ruby.rb', line 1358 def puts(obj) `var string=obj.m$toS&&obj.m$toS()||$q(''+obj)` `console.log(string._value.replace(/\\\\/g,'\\\\\\\\'))` return nil end |
#raise ⇒ Object
FIX: Incomplete
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 |
# File 'lib/source/ruby.rb', line 1365 def raise `var exception_class=c$RuntimeError,msg=$q('')` `if(arguments[0]&&arguments[0].m$isABool(c$Exception)){ var e=arguments[0]; }else{ if(arguments[0]&&arguments[0].m$class()==c$String){ msg=arguments[0]; }else{ if(arguments[0]!=null){ exception_class=arguments[0],msg=arguments[1]||msg; }; } }` `var e=e||exception_class.m$new(msg)` `e._stack=new Error().stack` `throw(e)` return nil end |
#rand(num = 0) ⇒ Object
call-seq:
rand(num = 0) -> numeric
Converts num to the integer max equivalent to num.to_i.abs. If max is zero, returns a pseudo-random floating point number greater than or equal to 0 and less than 1. Otherwise, returns a pseudo-random integer greater than or equal to zero and less than max.
rand #=> 0.7137224264409899
rand(10) #=> 2
rand(100) #=> 79
1396 1397 1398 1399 |
# File 'lib/source/ruby.rb', line 1396 def rand(num = 0) `var max=Math.abs(parseInt(num))` `max==0?Math.random():parseInt(Math.random()*max)` end |
#sleep(duration) ⇒ Object
call-seq:
sleep([duration]) -> integer
Suspends activity for duration seconds (which may be fractional), then returns the number of seconds slept (rounded). Zero arguments causes sleep to sleep forever.
Time.new #=> Wed Apr 09 08:56:32 CDT 2003
sleep 1.2 #=> 1
Time.new #=> Wed Apr 09 08:56:33 CDT 2003
sleep 1.9 #=> 2
Time.new #=> Wed Apr 09 08:56:35 CDT 2003
1414 1415 1416 1417 |
# File 'lib/source/ruby.rb', line 1414 def sleep(duration) `if(duration==null){while(true){};}else{var awaken=new(Date)().valueOf()+(1000*duration);while(new(Date)().valueOf()<awaken){};}` return `Math.round(duration)` end |
#sprintf(string) ⇒ Object
FIX: Incomplete
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 |
# File 'lib/source/ruby.rb', line 1420 def sprintf(string) `var i=1,source=string._value,result=[],m=$u,arg=$u,val=$u,str=$u,dL=$u,chr=$u,pad=$u; while(source){ if(m=source.match(/^[^%]+/)){result.push(m[0]);source=source.slice(m[0].length);continue;}; if(m=source.match(/^%%/)) {result.push('%'); source=source.slice(m[0].length);continue;}; // 1(0)2(wdth) 3(prec) 4(field-type ) if(m=source.match(/^%(0)?(\\d+)?(?:\\.(\\d+))?([bcdEefGgiopsuXx])/)){ arg = arguments[i]._value||arguments[i]; switch(m[4]){ case'b':str=parseFloat(arg).toString(2);break; case'c':str=String.fromCharCode(arg);break; case'd':val=parseInt(arg);str=''+val;break; case'E':val=parseFloat(arg);str=''+(m[3]?val.toExponential(m[3]):val.toExponential()).toUpperCase();break; case'e':val=parseFloat(arg);str=''+(m[3]?val.toExponential(m[3]):val.toExponential());break; case'f':val=parseFloat(arg);str=''+(m[3]?val.toFixed(m[3]):val);break; case'G':str='-FIX-';break; case'g':str='-FIX-';break; case'i':val=parseInt(arg);str=''+val;break; case'o':str=parseFloat(arg).toString(8);break; case'p':str=$q(arg).m$inspect()._value;break; case's':val=arg.m$toS&&arg.m$toS()._value||arg;str=(m[3]?val.slice(0,m[2]):val);break; case'u':val=parseInt(arg);str=''+(val<0?'..'+(Math.pow(2,32)+val):val);break; case'X':str=parseInt(arg).toString(16).toUpperCase();break; case'x':str=parseInt(arg).toString(16);break; }; if((dL=m[2]-str.length)!=0){for(chr=m[1]||' ',pad=[];dL>0;pad[--dL]=chr);}else{pad=[]}; result.push(pad.join('')+str); source=source.slice(m[0].length); i+=1; continue; }; throw('ArgumentError: malformed format string') }` return `$q(result.join(''))` end |
#x ⇒ Object
:nodoc:
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 |
# File 'lib/source/ruby.rb', line 1460 def x #:nodoc: #function m$sprintf(){ # var i=0,arg,f=arguments[i++],ary=[],m,p,c,x; # while (f) { # if(m=f.match(/^[^%]+/)){ # ary.push(m[0]); # }else{ // ['mtch',[1]:'digit-final?',[2]:'plus?',[3]:'0 or \' plus non-$ ?',[4]:'minus?',[5]:'digit?',[6]:'. plus digit?',[7]:'flag'] # if(m = f.match(/^%%/)){ary.push('%');}else{ # if(m=f.match(/^%(?:(\\d+)\\$)?(\\+)?(0|'[^$])?(-)?(\\d+)?(?:\\.(\\d+))?([bcdEefGgiopsuXx])/)){ # if(((arg = arguments[m[1] || i++])==null)||(arg==undefined)){throw('ArgumentError: too few arguments.');}; # if(/[^sp]/.test(m[7])&&!(typeof(arg)=='number')){throw('TypeError: can\\'t convert '+''+' into Integer');}; # switch (m[7]) { # case'b':str=arg.toString(2);break; # case'c':str=String.fromCharCode(arg);break; # case'd':str=parseInt(arg);break; # case'E':str=(m[6]?arg.toExponential(m[6]):arg.toExponential()).toUpperCase();break; # case'e':str=m[6]?arg.toExponential(m[6]):arg.toExponential();break; # case'f':str=m[6] ? parseFloat(arg).toFixed(m[6]) : parseFloat(arg); break; // Needs work # case'G':str='';break; # case'g':str='';break; # case'i':str=parseInt(arg);break; # case'o':str=arg.toString(8);break; # case'p':str=$q(arg).m$inspect();break; # case's':str=((arg = String(arg)) && m[6] ? arg.substring(0, m[6]) : arg); break; // Does this work? # case'u':str=arg<0?'..'+(Math.pow(2,32)+arg):arg;break; # case'X':str=arg.toString(16).toUpperCase();break; # case'x':str=arg.toString(16);break; # }; # a = (/[def]/.test(m[7]) && m[2] && str > 0 ? '+' + str : str); # c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' '; # x = m[5] - String(a).length; # if(m[5]){for(var c2=c,x2=x,ary2=[];x2>0;ary2[--x2]=c2);p=ary2.join('');}else{p='';}; # ary.push(m[4]?str+p:p+str); # }else{throw('ArgumentError: malformed format string');}; # }; # }; # f = f.substring(m[0].length); # } # return ary.join(''); #} end |