This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
#este programa emula un videojuego de coches en el que el usuario intenta llegar a la meta en menor tiempo posible | |
#Para observar cómo funciona basta con ver los dos primeros niveles, pues los otros son copiados de los anteriores | |
from random import random | |
from time import time | |
#Esta función se encargará de obtener aleatoriamente una posición para los coches enemigos | |
def azarf(x): | |
a=random() | |
if a<=(1/3.0): | |
azar=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Module | |
def optional | |
[self,:optional] | |
end | |
end | |
a = [Range, Fixnum.optional, String.optional] #=> [Range, [Fixnum, :optional], [String, :optional]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Module | |
VALID=[:optional, :rest_arg] | |
def is(value) | |
raise ArgumentError, "value must be one of #{VALID.join(',')}" unless VALID.include? value | |
[self,value] | |
end | |
end | |
a = [Range, Fixnum.is :optional, String.is :rest_arg] #=> [Range, [Fixnum, :optional], [String, :rest_arg]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Module | |
VALID=[:optional, :rest_arg] | |
VALID.each do |x| | |
define_method x do | |
[self, x] | |
end | |
end | |
end | |
a = [Range, Fixnum.optional, String.rest_arg] #=> [Range, [Fixnum, :optional], [String, :rest_arg]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output: | |
Hello from Ruby | |
JRuby rocks! | |
Serabe rocks! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rbconfig' | |
require 'java' | |
require '../../tool/signature' | |
class MyRubyClass | |
def helloWorld | |
puts "Hello from Ruby" | |
end | |
def goodbyeWorld(a,b="JRuby") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyObjectTest3 { | |
public static void main(String[] args) { | |
MyObject obj = new MyObject(); | |
obj.helloWorld(); | |
obj.goodbyeWorld(" rocks!"); | |
obj.goodbyeWorld(" rocks!", "Serabe"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiled from "MyObject.java.rb" | |
public class MyObject extends org.jruby.RubyObject{ | |
static {}; | |
public MyObject(); | |
public void helloWorld(); | |
public void goodbyeWorld(java.lang.String); | |
public void goodbyeWorld(java.lang.String, java.lang.String); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
serabe@Sylar:~/Programming/projects/ruby2java$ jruby src/compiler2.rb CloneableObject RubyClass examples/interface_example.rb | |
serabe@Sylar:~/Programming/projects/ruby2java$ javap CloneableObject | |
Compiled from "examples.interface_example.rb" | |
public class CloneableObject extends org.jruby.RubyObject implements java.lang.Cloneable{ | |
static {}; | |
public CloneableObject(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
serabe@Sylar:~/Programming/projects/ruby2java$ javap -c org.jruby.ruby2java.PackageClass | |
Compiled from "examples.package_example.rb" | |
public class org.jruby.ruby2java.PackageClass extends org.jruby.RubyObject{ | |
static {}; | |
Code: | |
0: invokestatic #13; //Method org/jruby/Ruby.getGlobalRuntime:()Lorg/jruby/Ruby; | |
3: invokevirtual #17; //Method org/jruby/Ruby.getLoadService:()Lorg/jruby/runtime/load/LoadService; | |
6: ldc #18; //String examples/package_example.rb | |
8: invokevirtual #24; //Method org/jruby/runtime/load/LoadService.require:(Ljava/lang/String;)Z | |
11: return |
OlderNewer