Javaの勉強会で発表した「JRubyで作るAPIサーバー」
先日開催された岡山Javaユーザー会勉強会で発表してきました。今回はSupported by RedBull(※1)ということで大阪からレッドブルガールがやってきたりなかなか面白い勉強会でした。 Javaのこと全然分かって無い人の発表なのに、みんな話を聞いてくれてありがとう!
JRubyで作るapiサーバー
View more presentations from kazuhisa01
スライド中で使用したデモプログラムは次のとおりです。
# Person.java
public class Person { private String myName; private int myAge; public void SetName(String name) { myName = name; } public String GetName() { return myName; } public void SetAge(int age) { myAge = age; } public int GetAge() { return myAge; } }
# person_spec.rb
require 'rubygems' require 'java' require 'rspec' import 'Person' describe "Person" do before do @person = Person.new @person.set_name("Yamamoto") @person.set_age(35) end it "名前が設定できること" do @person.get_name.should == "Yamamoto" end it "年齢が設定できること" do @person.get_age.should == 35 end end
# ext.rb
module Ext def name=(str) self.set_name(str) end def name self.get_name end def age=(a) self.set_age(a) end def age self.get_age end end
# person2.rb
require 'java' import 'Person' require 'ext' class Person include Ext end
# person_spec2.rb
require 'rubygems' require 'java' require 'rspec' # import 'Person' require 'person2' describe "Person" do before do @person = Person.new @person.name = "Yuuko" @person.age = 16 end it "名前が設定できること" do @person.name.should == "Yuuko" end it "年齢が設定できること" do @person.age.should == 16 end end
今回のプレゼンで感じたのは、やはりプレゼンは実働デモがあったほうが楽しいなということ。
そのせいでsafariがぴょんぴょんするのが止まらないようなトラブルもあるわけですが、Hello Worldが出現した時盛り上がったから結果オーライか(※2)。
岡山の勉強会は言語の壁を超えて、こういった横の繋がりがあるから面白いですね。他県の方もぜひ遊びに来てみてください。
(※1)ヘロイン中毒者が注射を打つのが大好きなように、プログラマはRedBullが大好きである。
(※2)なぜ私がプレゼン中safariの起動にあんなにこだわってたかというと、プロジェクタに接続したMy MacのFirefoxを開き、恥ずかしい履歴ページが表示されるのをためらったからである。マジで。