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
def create_listener(superclass, methodname, &block) | |
focus_listener_class = Class.new() do | |
include superclass | |
implement superclass | |
def initialize(methodname, &block) | |
@block = block | |
define_method(methodname) do | |
@block.call | |
end | |
#create_method(methodname, &block) |
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
def create_listener(superclass, methodname, &block) | |
focus_listener_class = Class.new() do | |
include superclass | |
implement superclass | |
def initialize(methodname, &block) | |
self.class.instance_eval do # <-- instance_eval makes this possible. :) | |
define_method(methodname, &block) | |
end | |
end | |
end |
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
module RCalc | |
require "java" | |
require "rswing" | |
require "frame" | |
require "text_field" | |
include RSwing::Components | |
include_package 'javax.swing' | |
include_package 'java.awt' |
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
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
module RSwing | |
module Components | |
module Events | |
module FocusEvents | |
FocusListener = java.awt.event.FocusListener | |
def on_focus(&block) | |
self.add_focus_listener(Listener.create(FocusListener, :focusGained ,&block)) | |
end | |
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 Test | |
def method(text) | |
if block_given? | |
yield "#{text} inside a block!" | |
else | |
puts "#{text} not in a block and just simply outputted to console." | |
end | |
end | |
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
f = File.new("myfile.txt", "r") # open a file with read-mode | |
# ... do some stuff with the file, like read its content, ouput it on the screen or whatever | |
# finally: close it! | |
f.close | |
# or: | |
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
Macintosh:examples bakkdoor$ jruby -cp jruby.jar numberconverter | |
Exception in thread "main" :1: jruby.jar:1: Invalid char `\3' ('') in expression (SyntaxError) | |
...internal jruby stack elided... | |
from (unknown).(unknown)(: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
Macintosh:examples bakkdoor$ java -cp jruby.jar:. numberconverter | |
Exception in thread "main" java.lang.NoClassDefFoundError: numberconverter (wrong name: examples/numberconverter) | |
at java.lang.ClassLoader.defineClass1(Native Method) | |
at java.lang.ClassLoader.defineClass(ClassLoader.java:675) | |
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) | |
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) | |
at java.net.URLClassLoader.access$100(URLClassLoader.java:56) | |
at java.net.URLClassLoader$1.run(URLClassLoader.java:195) | |
at java.security.AccessController.doPrivileged(Native Method) | |
at java.net.URLClassLoader.findClass(URLClassLoader.java:188) |
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
module Numberconverter | |
require "rubygems" | |
require "rswing" | |
include RSwing::Components | |
GridBagLayout = java.awt.GridBagLayout | |
frame = Frame.new "Numberconverter", |
OlderNewer