Created
December 7, 2012 07:42
-
-
Save ooharak/4231539 to your computer and use it in GitHub Desktop.
method chain feature for a Java object in 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
#method chain feature for a Java object in JRuby | |
class MethodChain | |
def initialize(underlying) | |
@underlying = underlying | |
end | |
def method_missing(name, *args, &block) | |
@underlying.send(name, *args, &block) | |
return self | |
end | |
def apply(&block) | |
yield self | |
end | |
def get | |
return @underlying | |
end | |
end | |
def example | |
require 'java' | |
frame = MethodChain.new(JavaxSwing::JFrame.new). | |
addKeyListener{|e| JavaLang::System::exit(0) if e.key_code == 033}. | |
apply{|f| f.contentPane.add JavaxSwing::JScrollPane.new('abc')}. | |
setPreferredSize(JavaAwt::Dimension.new(800,600)). | |
pack. | |
get | |
return frame | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment