SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
www.lycom.de
                                            www.hhtong.com

JRuby 和 Rails
让 Ruby 语言融入于 Java 项目
             QCon Beijing 2009

            骆古道 / Gudao Luo

 gudao.luo@gmail.com, @2009, 北京 , 中国 , 08.04.2009
骆古道 / Gudao Luo
●
    1983 年毕业于西北工业大学数理力学系
●
    1988 年国家公派留学德国 Augsburg 大学
    从事组合最优化理论学习和研究
●
    从 90 年代起在德国企业从事于软件工作
●
    《 JRuby 语言实战技术》作者
●
    个人博客为“道喜技术日记”
●
    Ruby 语言的现实
●
    JRuby/Ruby 和 Ruby 语言
●
    Rails 框架主要特点和优势
●
    JRuby 与 Java 项目
●
    Rails 的企业软件开发作用
●
    重要技术资源
Ruby 语言的现实
Apple Mac OS X 10.5 Leopard
系统标准配置
Ruby和Rails
Ruby 语言的现实
 NetBeans for Ruby
Ruby 语言的现实
JRuby是太阳公司投资的开源项目
Ruby 语言的现实
MacRuby是苹果公司投资的开源项目
Ruby 语言的现实
Ruby:
infoQ
六大社区
之一
Ruby 语言的现实
Ruby语言
成为
前十大
程序语言
之一
Ruby 语言的现实
Ruby语言图书世界
Ruby 语言的现实
真实JRuby软件世界
Ruby 语言的现实
真实Rails软件世界
JRuby/Ruby 和 Ruby 语言:基本名称

Ruby语言是一门软件编程语言
JRuby是Ruby语言的Java语言实现
Ruby/CRuby是Ruby语言的C语言实现
JRuby ≈ Ruby
JRuby/Ruby 和 Ruby 语言:   Ruby 语言
Ruby语言: 动态程序语言
Ruby语言: 100%面向对象程序语言
Ruby语言: 简洁和优美的程序语言
Ruby语言: 一切事情都是对象(Everything
is an object)
JRuby/Ruby 和 Ruby 语言:   JRuby
●
    JRuby:集成Java/Ruby语言强大功能
●
    JRuby:比CRuby实现的运行速度更快
●
    JRuby:自然线程
●
    JRuby:支持外来函数接口(FFI)
●
    JRuby:运行于Java虚拟机
●
    。。。
Ruby语言: 100%面向对象程序语言

- 1.class # Fixnum
- 3.14.class
  # Float
- [1, 'Ruby', :name].class
  # Array
- {:id => 11, :name => 'Luo' }.class
  # Hash
- (class Company;end).class
  # NilClass
Ruby 语言 : 简洁和优美的程序语言 (1)

# define a class
class Company; end

# use the class Company
ibm = Company.new
ibm.methods
Ruby 语言 : 简洁和优美的程序语言 (2)
# define a class Company
class Company
 attr_accessor :id
 def name; @name; end
 def name=(name); @name=name; end
end

# use the class Company
ibm = Company.new
ibm.id = 11; ibm.name = 'IBM'
Ruby 语言 : 一切事情都是对象
              ( Everything is an object )
         “有、无相生” “天下万物生于有,有生于无” – 老子


ibm.class
=> Company
ibm.class.superclass
=> Object
ibm.class.superclass.superclass
=> nil
nil.class
=> NilClass
Rails 框架主要特点和优势
Rails框架: Web软件框架
Rails框架: 数据库持久性框架
Rails框架: MVC(Model-View-Control)框架
Rails框架: DSL(Domain Specific Language)
Rails框架: Ruby实现的Web软件框架
Rails 框架主要特点和优势
视图:
css, ajax,
iphone, html,
pdf, xml,
json, xls,
js, ...
Rails 框架主要特点和优势
控制器:
access
cache
logic
...
Rails 框架主要特点和优势
模型:
migration,
validation,
status,
finder,
callbacks,
...
JRuby 与 Java 项目
●
    Java 项目向 JRuby 项目迁移
●
    基于 Java 运行环境下的 JRuby 项目
●
    基于现有 Java 企业项目的 JRuby 项目
●
    基于 Java 资源的 JRuby 项目
●
    利用 JRuby 资源开发 Java 项目
JRuby 与 Java 项目
●   JRuby on Android
●   JRuby on Swing
●   JRuby on Jackrabbit (JCR=Java Content Repository)
●   JRuby on Hibernate (ORM, Ribs)
●   JRuby on JBoss / GlassFish (Java Application Server)
●
    JRuby on 。。。
JRuby 与 Java 项目:   JRuby 实例演示 (1)
# Import Java packages
include Java
import javax.swing.JFrame
frame = JFrame.new("Hello Swing")

# Show frame
frame.set_default_close_operation(JFrame::
EXIT_ON_CLOSE)
frame.pack
frame.visible = true
JRuby 与 Java 项目:   JRuby 实例演示 (2)
# Create a button for the frame
button = javax.swing.JButton.new(" 点击
我 !")

# Add the button to the frame
frame.get_content_pane.add(button)
frame.visible = true
JRuby 与 Java 项目:   JRuby 实例演示 (3)
# Add an action for the button
button.add_action_listener do |evt|
javax.swing.JOptionPane.showMessageDialog(nil,
<<EOS)
<html> 来自 <b><u>JRuby</u></b> 问候! <br>
Button '#{evt.getActionCommand()}' clicked.
EOS
end
JRuby 与 Java 项目:   JRuby on Android
JRuby 与 Java 项目:   JRuby on Android
                        实例演示
●   Android on Mac OS X 10.5.6
●   JRuby on Android
●
    创建 Android 应用实例
●
    运行 JRuby 程序
Rails 的企业软件开发作用
●
    基于 Ruby 语言的数据库迁移技术
●
    基于 Ruby 语言的测试框架 Cucumber
●
    基于 Ruby 语言的易和快 PDF 生成库
    Prawn
●
    基于 Ruby 语言的。。。
Rails 框架优势实例:   数据库迁移技术 (1)
Rails    迁移:     使用Ruby语言实现
Rails    迁移:     不重复你自己(DRY)
Rails    迁移:     支持数据/模式迁移
Rails    迁移:     允许嵌入模型逻辑于数据迁移(而SQL 脚
本难以做到)

Rails 迁移: 独立于数据库(而 SQL 脚本不独立)
Rails 迁移: 允许嵌入SQL语句(例如存储过程或约束)
(而有些 ORM 并不支持)
Rails 框架优势实例:    数据库迁移技术 (2)
class CreateCustomers < ActiveRecord::Migration
 def self.up
   create_table :customers do |t|
    t.string :name,    :limit => 30, :null => false
    t.integer :age
    t.binary :photo,   :limit => 2.megabytes
    t.timestamps
   end
   Customer.create :name => "David", :age => "32"
 end

 def self.down; drop_table :customers; end
end
Rails 框架优势实例:      数据库迁移技术 (3)
class ChangeAlbumYearToInteger < ActiveRecord::Migration
 def self.up
  add_column :albums, :year_int, :integer, :limit => 4
  Album.reset_column_information
  say_with_time "Updating albums" do
   albums = Album.find_all
   albums.each do |a|
     a.update_attribute(:year_int, a.year.to_i)
     say "#{a.release_name} updated!", true
   end
  end
# ...
Rails 框架优势实例:测试框架 Cucumber(1)
Cucumber是跨计算机语言的代码测试工具
Cucumber是使用本地化语言的代码测试工具
Cucumber是集成多种测试工具于一体的工具
Cucumber彻底分离测试描述(文字工作者)
与描述实现(软件工作者)
Cucumber更加人性化,更加语言化,更加简单化
Rails 框架优势实例:     测试框架 Cucumber(2)
功能 : 管理帖子
 为了能够控制“帖子 MVC”
 作为软件普通用户
 我要完成“帖子 MCV” 创建和删除帖子的功能 

 场景 : 创建一个新的帖子
  假如 我已经在创建新帖子页面
  当 我在输入框 <post_title> 中输入内容 <lycom.de 是什么网站 >
  而且 我在输入框 <post_body> 中输入内容 <lycom.de 是一个 Ruby/Rails 技术新闻博客 >
  而且 我点击按钮 <Create>
  那么 我应该看到 <lycom.de 是什么网站 >
  而且 我应该看到 <lycom.de 是一个 Ruby/Rails 技术新闻博客 >
 场景 : 删除第一个帖子
  假如 存在 <4> 个帖子
  当 我删除第一个帖子
  那么 还应该有 <3> 个帖子
Rails 实例演示 (1)
# create rails application in system shell
rails demo && cd demo
./script/generate scaffold blog title:string body:text
rake db:migrate
./script/server
# use the rails application in browser
open http://0.0.0.0:3000
# debug, test and use the rails application in rails shell
./script/console
Rails 实例演示 (2)
# install rails edge current version 2.3
mkdir -p myapp/vendor && cd myapp
git clone git://github.com/rails/rails.git vendor/rails
ruby vendor/rails/railties/bin/rails -v
# create a rails generator file: rails_template.rb
generate(:scaffold, "blog title:string body:text")
rake("db:migrate")

# create rails 2.3 application with rails template
ruby vendor/rails/railties/bin/rails . -m rails_template.rb
重要技术资源 (1)
    JRuby/Ruby/Rails 官方网站
●   http://www.ruby-lang.org
●   http://rubyonrails.org/
●   http://jruby.codehaus.org/
重要技术资源 (2)
    JRubyRuby/Rails 博客
●   http://www.rubyinside.com/
●   htp://asciicasts.com/
●   htp://ryandaigle.com/
●   htp://www.jrubyinside.com/


    视频 Rails 博客 : http://railscasts.com/
重要技术资源 (3)

    Ruby/JRuby/Rails 图书
●
    《应用 Rails 进行敏捷 Web 开发》 http://www.dearbook.com.cn/book/109115
●
    《 Programming Ruby 中文版》 http://www.dearbook.com.cn/book/109114
●
    《 JRuby 语言实战技术》 http://www.china-pub.com/39945

Contenu connexe

Tendances

Btrace intro(撒迦)
Btrace intro(撒迦)Btrace intro(撒迦)
Btrace intro(撒迦)ykdsg
 
Nodejs部门分享
Nodejs部门分享Nodejs部门分享
Nodejs部门分享zffl
 
如何用JDK8實作一個小型的關聯式資料庫系統
如何用JDK8實作一個小型的關聯式資料庫系統如何用JDK8實作一個小型的關聯式資料庫系統
如何用JDK8實作一個小型的關聯式資料庫系統なおき きしだ
 
Ruby rails分享
Ruby rails分享Ruby rails分享
Ruby rails分享Cam Song
 
Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00Justin Lin
 
以Code igniter為基礎的網頁前端程式設計
以Code igniter為基礎的網頁前端程式設計以Code igniter為基礎的網頁前端程式設計
以Code igniter為基礎的網頁前端程式設計Amigo 陳兆祥
 
Java cpu
Java cpuJava cpu
Java cpuykdsg
 
Getting started with test automation
Getting started with test automationGetting started with test automation
Getting started with test automationIvan Wei
 
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式Will Huang
 
Node.js中间件 connect模块深入浅出
Node.js中间件 connect模块深入浅出Node.js中间件 connect模块深入浅出
Node.js中间件 connect模块深入浅出Eric Xiao
 
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)Kris Mok
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介GO LL
 
使用Javascript及HTML5打造協同運作系統
使用Javascript及HTML5打造協同運作系統使用Javascript及HTML5打造協同運作系統
使用Javascript及HTML5打造協同運作系統Hsu Ping Feng
 
2012 java two-desktop-appliction-using-j-ruby-with-swt
2012 java two-desktop-appliction-using-j-ruby-with-swt2012 java two-desktop-appliction-using-j-ruby-with-swt
2012 java two-desktop-appliction-using-j-ruby-with-swttka
 
TypeScript 綜合格鬥技
TypeScript 綜合格鬥技TypeScript 綜合格鬥技
TypeScript 綜合格鬥技Will Huang
 
Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Will Huang
 
如何在 Java App 中導入 Scala
如何在 Java App 中導入 Scala如何在 Java App 中導入 Scala
如何在 Java App 中導入 Scalajavatwo2011
 

Tendances (20)

Btrace intro(撒迦)
Btrace intro(撒迦)Btrace intro(撒迦)
Btrace intro(撒迦)
 
Nodejs部门分享
Nodejs部门分享Nodejs部门分享
Nodejs部门分享
 
如何用JDK8實作一個小型的關聯式資料庫系統
如何用JDK8實作一個小型的關聯式資料庫系統如何用JDK8實作一個小型的關聯式資料庫系統
如何用JDK8實作一個小型的關聯式資料庫系統
 
Ruby基础培训
Ruby基础培训Ruby基础培训
Ruby基础培训
 
Ruby rails分享
Ruby rails分享Ruby rails分享
Ruby rails分享
 
Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00Java Tutorial:Learn Java in 06:00:00
Java Tutorial:Learn Java in 06:00:00
 
以Code igniter為基礎的網頁前端程式設計
以Code igniter為基礎的網頁前端程式設計以Code igniter為基礎的網頁前端程式設計
以Code igniter為基礎的網頁前端程式設計
 
Java cpu
Java cpuJava cpu
Java cpu
 
Getting started with test automation
Getting started with test automationGetting started with test automation
Getting started with test automation
 
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
 
Node.js中间件 connect模块深入浅出
Node.js中间件 connect模块深入浅出Node.js中间件 connect模块深入浅出
Node.js中间件 connect模块深入浅出
 
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)
 
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
 
使用Javascript及HTML5打造協同運作系統
使用Javascript及HTML5打造協同運作系統使用Javascript及HTML5打造協同運作系統
使用Javascript及HTML5打造協同運作系統
 
Java bytecode
Java bytecodeJava bytecode
Java bytecode
 
2012 java two-desktop-appliction-using-j-ruby-with-swt
2012 java two-desktop-appliction-using-j-ruby-with-swt2012 java two-desktop-appliction-using-j-ruby-with-swt
2012 java two-desktop-appliction-using-j-ruby-with-swt
 
TypeScript 綜合格鬥技
TypeScript 綜合格鬥技TypeScript 綜合格鬥技
TypeScript 綜合格鬥技
 
Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)Visual Studio 2017 新功能探索 (Study4.TW)
Visual Studio 2017 新功能探索 (Study4.TW)
 
笔记
笔记笔记
笔记
 
如何在 Java App 中導入 Scala
如何在 Java App 中導入 Scala如何在 Java App 中導入 Scala
如何在 Java App 中導入 Scala
 

Similaire à J Ruby和Rails 让Ruby语言融入Java项目

從 Java programmer 的觀點看 ruby
從 Java programmer 的觀點看 ruby從 Java programmer 的觀點看 ruby
從 Java programmer 的觀點看 ruby建興 王
 
Javascript primer plus
Javascript primer plusJavascript primer plus
Javascript primer plusDongxu Yao
 
[OSDC12]相依性管理 - 以Ruby開發為例
[OSDC12]相依性管理 - 以Ruby開發為例[OSDC12]相依性管理 - 以Ruby開發為例
[OSDC12]相依性管理 - 以Ruby開發為例YC Ling
 
第1章 入门
第1章 入门第1章 入门
第1章 入门Runa Jiang
 
Node js实践
Node js实践Node js实践
Node js实践myzykj
 
Rails ABC
Rails ABCRails ABC
Rails ABCqtlove
 
Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Wen-Tien Chang
 
The ruby-way
The ruby-wayThe ruby-way
The ruby-wayfangdeng
 
從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用謝 宗穎
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨Wen-Tien Chang
 
Java 1(Java概述)
Java 1(Java概述)Java 1(Java概述)
Java 1(Java概述)xzdbd
 
Grails敏捷项目开发
Grails敏捷项目开发Grails敏捷项目开发
Grails敏捷项目开发Michael Yan
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和javasulong
 
D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践Jackson Tian
 
Build desktop app_by_xulrunner
Build desktop app_by_xulrunnerBuild desktop app_by_xulrunner
Build desktop app_by_xulrunnerRack Lin
 
Full stack-development with node js
Full stack-development with node jsFull stack-development with node js
Full stack-development with node jsXuefeng Zhang
 
Ksdg 使用 ruby on rails 快速打造你的 web app
Ksdg   使用 ruby on rails 快速打造你的 web appKsdg   使用 ruby on rails 快速打造你的 web app
Ksdg 使用 ruby on rails 快速打造你的 web appEddie Lee
 
前端自動化工具
前端自動化工具前端自動化工具
前端自動化工具國昭 張
 

Similaire à J Ruby和Rails 让Ruby语言融入Java项目 (20)

第七組
第七組第七組
第七組
 
從 Java programmer 的觀點看 ruby
從 Java programmer 的觀點看 ruby從 Java programmer 的觀點看 ruby
從 Java programmer 的觀點看 ruby
 
Javascript primer plus
Javascript primer plusJavascript primer plus
Javascript primer plus
 
[OSDC12]相依性管理 - 以Ruby開發為例
[OSDC12]相依性管理 - 以Ruby開發為例[OSDC12]相依性管理 - 以Ruby開發為例
[OSDC12]相依性管理 - 以Ruby開發為例
 
第1章 入门
第1章 入门第1章 入门
第1章 入门
 
Node js实践
Node js实践Node js实践
Node js实践
 
Rails ABC
Rails ABCRails ABC
Rails ABC
 
Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛Ruby Rails 老司機帶飛
Ruby Rails 老司機帶飛
 
The ruby-way
The ruby-wayThe ruby-way
The ruby-way
 
從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用
 
⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨⼤語⾔模型 LLM 應⽤開發入⾨
⼤語⾔模型 LLM 應⽤開發入⾨
 
Java 1(Java概述)
Java 1(Java概述)Java 1(Java概述)
Java 1(Java概述)
 
Grails敏捷项目开发
Grails敏捷项目开发Grails敏捷项目开发
Grails敏捷项目开发
 
漫谈php和java
漫谈php和java漫谈php和java
漫谈php和java
 
D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践D2_Node在淘宝的应用实践
D2_Node在淘宝的应用实践
 
Build desktop app_by_xulrunner
Build desktop app_by_xulrunnerBuild desktop app_by_xulrunner
Build desktop app_by_xulrunner
 
Full stack-development with node js
Full stack-development with node jsFull stack-development with node js
Full stack-development with node js
 
Ksdg 使用 ruby on rails 快速打造你的 web app
Ksdg   使用 ruby on rails 快速打造你的 web appKsdg   使用 ruby on rails 快速打造你的 web app
Ksdg 使用 ruby on rails 快速打造你的 web app
 
前端自動化工具
前端自動化工具前端自動化工具
前端自動化工具
 
beidakejian
beidakejianbeidakejian
beidakejian
 

Plus de George Ang

Wrapper induction construct wrappers automatically to extract information f...
Wrapper induction   construct wrappers automatically to extract information f...Wrapper induction   construct wrappers automatically to extract information f...
Wrapper induction construct wrappers automatically to extract information f...George Ang
 
Opinion mining and summarization
Opinion mining and summarizationOpinion mining and summarization
Opinion mining and summarizationGeorge Ang
 
Huffman coding
Huffman codingHuffman coding
Huffman codingGeorge Ang
 
Do not crawl in the dust 
different ur ls similar text
Do not crawl in the dust 
different ur ls similar textDo not crawl in the dust 
different ur ls similar text
Do not crawl in the dust 
different ur ls similar textGeorge Ang
 
大规模数据处理的那些事儿
大规模数据处理的那些事儿大规模数据处理的那些事儿
大规模数据处理的那些事儿George Ang
 
腾讯大讲堂02 休闲游戏发展的文化趋势
腾讯大讲堂02 休闲游戏发展的文化趋势腾讯大讲堂02 休闲游戏发展的文化趋势
腾讯大讲堂02 休闲游戏发展的文化趋势George Ang
 
腾讯大讲堂03 qq邮箱成长历程
腾讯大讲堂03 qq邮箱成长历程腾讯大讲堂03 qq邮箱成长历程
腾讯大讲堂03 qq邮箱成长历程George Ang
 
腾讯大讲堂04 im qq
腾讯大讲堂04 im qq腾讯大讲堂04 im qq
腾讯大讲堂04 im qqGeorge Ang
 
腾讯大讲堂05 面向对象应对之道
腾讯大讲堂05 面向对象应对之道腾讯大讲堂05 面向对象应对之道
腾讯大讲堂05 面向对象应对之道George Ang
 
腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化George Ang
 
腾讯大讲堂07 qq空间
腾讯大讲堂07 qq空间腾讯大讲堂07 qq空间
腾讯大讲堂07 qq空间George Ang
 
腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨George Ang
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站George Ang
 
腾讯大讲堂01 移动qq产品发展历程
腾讯大讲堂01 移动qq产品发展历程腾讯大讲堂01 移动qq产品发展历程
腾讯大讲堂01 移动qq产品发展历程George Ang
 
腾讯大讲堂10 customer engagement
腾讯大讲堂10 customer engagement腾讯大讲堂10 customer engagement
腾讯大讲堂10 customer engagementGeorge Ang
 
腾讯大讲堂11 拍拍ce工作经验分享
腾讯大讲堂11 拍拍ce工作经验分享腾讯大讲堂11 拍拍ce工作经验分享
腾讯大讲堂11 拍拍ce工作经验分享George Ang
 
腾讯大讲堂14 qq直播(qq live) 介绍
腾讯大讲堂14 qq直播(qq live) 介绍腾讯大讲堂14 qq直播(qq live) 介绍
腾讯大讲堂14 qq直播(qq live) 介绍George Ang
 
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍George Ang
 
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍George Ang
 
腾讯大讲堂16 产品经理工作心得分享
腾讯大讲堂16 产品经理工作心得分享腾讯大讲堂16 产品经理工作心得分享
腾讯大讲堂16 产品经理工作心得分享George Ang
 

Plus de George Ang (20)

Wrapper induction construct wrappers automatically to extract information f...
Wrapper induction   construct wrappers automatically to extract information f...Wrapper induction   construct wrappers automatically to extract information f...
Wrapper induction construct wrappers automatically to extract information f...
 
Opinion mining and summarization
Opinion mining and summarizationOpinion mining and summarization
Opinion mining and summarization
 
Huffman coding
Huffman codingHuffman coding
Huffman coding
 
Do not crawl in the dust 
different ur ls similar text
Do not crawl in the dust 
different ur ls similar textDo not crawl in the dust 
different ur ls similar text
Do not crawl in the dust 
different ur ls similar text
 
大规模数据处理的那些事儿
大规模数据处理的那些事儿大规模数据处理的那些事儿
大规模数据处理的那些事儿
 
腾讯大讲堂02 休闲游戏发展的文化趋势
腾讯大讲堂02 休闲游戏发展的文化趋势腾讯大讲堂02 休闲游戏发展的文化趋势
腾讯大讲堂02 休闲游戏发展的文化趋势
 
腾讯大讲堂03 qq邮箱成长历程
腾讯大讲堂03 qq邮箱成长历程腾讯大讲堂03 qq邮箱成长历程
腾讯大讲堂03 qq邮箱成长历程
 
腾讯大讲堂04 im qq
腾讯大讲堂04 im qq腾讯大讲堂04 im qq
腾讯大讲堂04 im qq
 
腾讯大讲堂05 面向对象应对之道
腾讯大讲堂05 面向对象应对之道腾讯大讲堂05 面向对象应对之道
腾讯大讲堂05 面向对象应对之道
 
腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化
 
腾讯大讲堂07 qq空间
腾讯大讲堂07 qq空间腾讯大讲堂07 qq空间
腾讯大讲堂07 qq空间
 
腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨腾讯大讲堂08 可扩展web架构探讨
腾讯大讲堂08 可扩展web架构探讨
 
腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站腾讯大讲堂09 如何建设高性能网站
腾讯大讲堂09 如何建设高性能网站
 
腾讯大讲堂01 移动qq产品发展历程
腾讯大讲堂01 移动qq产品发展历程腾讯大讲堂01 移动qq产品发展历程
腾讯大讲堂01 移动qq产品发展历程
 
腾讯大讲堂10 customer engagement
腾讯大讲堂10 customer engagement腾讯大讲堂10 customer engagement
腾讯大讲堂10 customer engagement
 
腾讯大讲堂11 拍拍ce工作经验分享
腾讯大讲堂11 拍拍ce工作经验分享腾讯大讲堂11 拍拍ce工作经验分享
腾讯大讲堂11 拍拍ce工作经验分享
 
腾讯大讲堂14 qq直播(qq live) 介绍
腾讯大讲堂14 qq直播(qq live) 介绍腾讯大讲堂14 qq直播(qq live) 介绍
腾讯大讲堂14 qq直播(qq live) 介绍
 
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
 
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
腾讯大讲堂15 市场研究及数据分析理念及方法概要介绍
 
腾讯大讲堂16 产品经理工作心得分享
腾讯大讲堂16 产品经理工作心得分享腾讯大讲堂16 产品经理工作心得分享
腾讯大讲堂16 产品经理工作心得分享
 

J Ruby和Rails 让Ruby语言融入Java项目

  • 1. www.lycom.de www.hhtong.com JRuby 和 Rails 让 Ruby 语言融入于 Java 项目 QCon Beijing 2009 骆古道 / Gudao Luo gudao.luo@gmail.com, @2009, 北京 , 中国 , 08.04.2009
  • 2. 骆古道 / Gudao Luo ● 1983 年毕业于西北工业大学数理力学系 ● 1988 年国家公派留学德国 Augsburg 大学 从事组合最优化理论学习和研究 ● 从 90 年代起在德国企业从事于软件工作 ● 《 JRuby 语言实战技术》作者 ● 个人博客为“道喜技术日记”
  • 3. Ruby 语言的现实 ● JRuby/Ruby 和 Ruby 语言 ● Rails 框架主要特点和优势 ● JRuby 与 Java 项目 ● Rails 的企业软件开发作用 ● 重要技术资源
  • 4. Ruby 语言的现实 Apple Mac OS X 10.5 Leopard 系统标准配置 Ruby和Rails
  • 13. JRuby/Ruby 和 Ruby 语言:基本名称 Ruby语言是一门软件编程语言 JRuby是Ruby语言的Java语言实现 Ruby/CRuby是Ruby语言的C语言实现 JRuby ≈ Ruby
  • 14. JRuby/Ruby 和 Ruby 语言: Ruby 语言 Ruby语言: 动态程序语言 Ruby语言: 100%面向对象程序语言 Ruby语言: 简洁和优美的程序语言 Ruby语言: 一切事情都是对象(Everything is an object)
  • 15. JRuby/Ruby 和 Ruby 语言: JRuby ● JRuby:集成Java/Ruby语言强大功能 ● JRuby:比CRuby实现的运行速度更快 ● JRuby:自然线程 ● JRuby:支持外来函数接口(FFI) ● JRuby:运行于Java虚拟机 ● 。。。
  • 16. Ruby语言: 100%面向对象程序语言 - 1.class # Fixnum - 3.14.class # Float - [1, 'Ruby', :name].class # Array - {:id => 11, :name => 'Luo' }.class # Hash - (class Company;end).class # NilClass
  • 17. Ruby 语言 : 简洁和优美的程序语言 (1) # define a class class Company; end # use the class Company ibm = Company.new ibm.methods
  • 18. Ruby 语言 : 简洁和优美的程序语言 (2) # define a class Company class Company attr_accessor :id def name; @name; end def name=(name); @name=name; end end # use the class Company ibm = Company.new ibm.id = 11; ibm.name = 'IBM'
  • 19. Ruby 语言 : 一切事情都是对象 ( Everything is an object ) “有、无相生” “天下万物生于有,有生于无” – 老子 ibm.class => Company ibm.class.superclass => Object ibm.class.superclass.superclass => nil nil.class => NilClass
  • 20. Rails 框架主要特点和优势 Rails框架: Web软件框架 Rails框架: 数据库持久性框架 Rails框架: MVC(Model-View-Control)框架 Rails框架: DSL(Domain Specific Language) Rails框架: Ruby实现的Web软件框架
  • 24. JRuby 与 Java 项目 ● Java 项目向 JRuby 项目迁移 ● 基于 Java 运行环境下的 JRuby 项目 ● 基于现有 Java 企业项目的 JRuby 项目 ● 基于 Java 资源的 JRuby 项目 ● 利用 JRuby 资源开发 Java 项目
  • 25. JRuby 与 Java 项目 ● JRuby on Android ● JRuby on Swing ● JRuby on Jackrabbit (JCR=Java Content Repository) ● JRuby on Hibernate (ORM, Ribs) ● JRuby on JBoss / GlassFish (Java Application Server) ● JRuby on 。。。
  • 26. JRuby 与 Java 项目: JRuby 实例演示 (1) # Import Java packages include Java import javax.swing.JFrame frame = JFrame.new("Hello Swing") # Show frame frame.set_default_close_operation(JFrame:: EXIT_ON_CLOSE) frame.pack frame.visible = true
  • 27. JRuby 与 Java 项目: JRuby 实例演示 (2) # Create a button for the frame button = javax.swing.JButton.new(" 点击 我 !") # Add the button to the frame frame.get_content_pane.add(button) frame.visible = true
  • 28. JRuby 与 Java 项目: JRuby 实例演示 (3) # Add an action for the button button.add_action_listener do |evt| javax.swing.JOptionPane.showMessageDialog(nil, <<EOS) <html> 来自 <b><u>JRuby</u></b> 问候! <br> Button '#{evt.getActionCommand()}' clicked. EOS end
  • 29. JRuby 与 Java 项目: JRuby on Android
  • 30. JRuby 与 Java 项目: JRuby on Android 实例演示 ● Android on Mac OS X 10.5.6 ● JRuby on Android ● 创建 Android 应用实例 ● 运行 JRuby 程序
  • 31. Rails 的企业软件开发作用 ● 基于 Ruby 语言的数据库迁移技术 ● 基于 Ruby 语言的测试框架 Cucumber ● 基于 Ruby 语言的易和快 PDF 生成库 Prawn ● 基于 Ruby 语言的。。。
  • 32. Rails 框架优势实例: 数据库迁移技术 (1) Rails 迁移: 使用Ruby语言实现 Rails 迁移: 不重复你自己(DRY) Rails 迁移: 支持数据/模式迁移 Rails 迁移: 允许嵌入模型逻辑于数据迁移(而SQL 脚 本难以做到) Rails 迁移: 独立于数据库(而 SQL 脚本不独立) Rails 迁移: 允许嵌入SQL语句(例如存储过程或约束) (而有些 ORM 并不支持)
  • 33. Rails 框架优势实例: 数据库迁移技术 (2) class CreateCustomers < ActiveRecord::Migration def self.up create_table :customers do |t| t.string :name, :limit => 30, :null => false t.integer :age t.binary :photo, :limit => 2.megabytes t.timestamps end Customer.create :name => "David", :age => "32" end def self.down; drop_table :customers; end end
  • 34. Rails 框架优势实例: 数据库迁移技术 (3) class ChangeAlbumYearToInteger < ActiveRecord::Migration def self.up add_column :albums, :year_int, :integer, :limit => 4 Album.reset_column_information say_with_time "Updating albums" do albums = Album.find_all albums.each do |a| a.update_attribute(:year_int, a.year.to_i) say "#{a.release_name} updated!", true end end # ...
  • 36. Rails 框架优势实例: 测试框架 Cucumber(2) 功能 : 管理帖子 为了能够控制“帖子 MVC” 作为软件普通用户 我要完成“帖子 MCV” 创建和删除帖子的功能  场景 : 创建一个新的帖子 假如 我已经在创建新帖子页面 当 我在输入框 <post_title> 中输入内容 <lycom.de 是什么网站 > 而且 我在输入框 <post_body> 中输入内容 <lycom.de 是一个 Ruby/Rails 技术新闻博客 > 而且 我点击按钮 <Create> 那么 我应该看到 <lycom.de 是什么网站 > 而且 我应该看到 <lycom.de 是一个 Ruby/Rails 技术新闻博客 > 场景 : 删除第一个帖子 假如 存在 <4> 个帖子 当 我删除第一个帖子 那么 还应该有 <3> 个帖子
  • 37. Rails 实例演示 (1) # create rails application in system shell rails demo && cd demo ./script/generate scaffold blog title:string body:text rake db:migrate ./script/server # use the rails application in browser open http://0.0.0.0:3000 # debug, test and use the rails application in rails shell ./script/console
  • 38. Rails 实例演示 (2) # install rails edge current version 2.3 mkdir -p myapp/vendor && cd myapp git clone git://github.com/rails/rails.git vendor/rails ruby vendor/rails/railties/bin/rails -v # create a rails generator file: rails_template.rb generate(:scaffold, "blog title:string body:text") rake("db:migrate") # create rails 2.3 application with rails template ruby vendor/rails/railties/bin/rails . -m rails_template.rb
  • 39. 重要技术资源 (1) JRuby/Ruby/Rails 官方网站 ● http://www.ruby-lang.org ● http://rubyonrails.org/ ● http://jruby.codehaus.org/
  • 40. 重要技术资源 (2) JRubyRuby/Rails 博客 ● http://www.rubyinside.com/ ● htp://asciicasts.com/ ● htp://ryandaigle.com/ ● htp://www.jrubyinside.com/ 视频 Rails 博客 : http://railscasts.com/
  • 41. 重要技术资源 (3) Ruby/JRuby/Rails 图书 ● 《应用 Rails 进行敏捷 Web 开发》 http://www.dearbook.com.cn/book/109115 ● 《 Programming Ruby 中文版》 http://www.dearbook.com.cn/book/109114 ● 《 JRuby 语言实战技术》 http://www.china-pub.com/39945