Skip to content

Instantly share code, notes, and snippets.

View Serabe's full-sized avatar

Sergio Arbeo Serabe

View GitHub Profile
#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
class Module
def optional
[self,:optional]
end
end
a = [Range, Fixnum.optional, String.optional] #=> [Range, [Fixnum, :optional], [String, :optional]]
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]]
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]]
Output:
Hello from Ruby
JRuby rocks!
Serabe rocks!
require 'rbconfig'
require 'java'
require '../../tool/signature'
class MyRubyClass
def helloWorld
puts "Hello from Ruby"
end
def goodbyeWorld(a,b="JRuby")
public class MyObjectTest3 {
public static void main(String[] args) {
MyObject obj = new MyObject();
obj.helloWorld();
obj.goodbyeWorld(" rocks!");
obj.goodbyeWorld(" rocks!", "Serabe");
}
}
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);
}
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();
}
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