A Programmer's Best Friend, Ruby

SN
by Seiya Nishizawa7 views·Updated Mar 11, 2011
Powered by AI

Need to present on this topic?

Create your own polished presentation in minutes. Just describe what you need.

Free to try, no credit card required

Transcript

ル ビ ー

オブジェクト指向スクリプト言語

えっ

Rubyよりも

このプレゼンソフトの方が気になる?

相互にメッセージ (message) を送りあうオブジェクト (object) の集まりとしてプログラムを構成する技法 (wikipedia)

???

イメージ

例: 西澤誠也さんの現住所が知りたい

手続き型プログラミング

お役所に行き、西澤誠也さんの住民票番号(住基ネットのID番号)を伝えて現住所を教えてもらう

つまり、

希望する処理ができる偉い人 (function, subroutin) がいて、

その人に(必要であればデータを渡して)、希望する処理をしてもらう

オブジェクト指向プログラミング

西澤誠也さん本人に尋ねて、現住所を教えてもらう

つまり、

希望する処理の対象 (object) に希望する処理をお願いする

日本語が使える!

日本人が開発

日本語マニュアルが充実!

配列を壊してもsegfしない!

% cat test.rb

require "narray"

a = NArray.float(10)

a[100] = 0.0

% ruby test.rb

test.rb:3:in `[]=': index out of range (IndexError)

from test.rb:3

ループをできるだけ排除する

NArray を巧みに使う

実行が遅いって聞いたことが...

開発・デバッグの時間 短い

開発・デバック時間 + 実行時間

短い

Segmentation Fault

Fortran

program main

 integer, parameter :: MAX_ADD_LEN = 30

 integer :: id

 id = 1

 write(*,*) address(id)

contains

 function address(id)

  character(len=MAX_ADD_LEN) :: addresses(1) = ('*****, Kobe City, Hyogo')

  integer, intent(in) :: id

  character(len=MAX_ADD_LEN) :: address

  address = addresses(id)

 end function

end program main

Ruby

class Person

 def initialize(name, address)

  @name = name

  @address = address

 end

 def name

  return @name

 end

 def address

  return @address

 end

end

seiya = Persion.new("西澤誠也", "兵庫県神戸市*****") # 西澤オブジェクト

seiya.address #=> "兵庫県神戸市*****"

# 分岐

if a == 1

 p "a is 1"

elsif a == 2

 p "a is 2"

else

 p "a is neither 1 and 2"

end

case a

when 1

 p "a is 1"

when 2

 p "a is 2"

else

 p "a is neither 1 and 2"

end

# ループ

for i in 0..2 # i=0,1,2

 p i

end

i=0

while i<3

 p i

 i += 1

end

3.times do |i| # i=0,1, 3

 p i

end

[0,2,4].each do |i| # i=0,2,4

 p i

end

イタレーターと呼ばれる、Rubyの特徴の一つ

# 例外(エラー)処理

begin

 p a # aという変数は定義されていない

rescue # 例外が挙がると実行される

 p "a is not defined"

end

begin

p a

rescure

p "a is not defined"

ensure # 必ずに実行される

p "ok"

end

include Math # 数学演算利用時のおまじない

a = 1

b = 2

c = a + b #=> 3

d = c * 3 #=> 9

e = sin(PI/4) #=> sqrt(2.0)/2

f = E**(log(2)) #=> 2.0

require "narray" # 高速な配列ライブラリ

a = NArray.float(4) # 長さ4 の倍精度浮動小数の配列

b = NArray.sfloat(4) # 単精度だって 値は 0 で初期化されている

a[0] = 1 # 配列要素へのアクセスは [] を使う

             # 配列のインデックスは 0 から始まる (C のスタイル)

b[0..2] = 1 # 部分配列 b[0], b[1], b[2]

c = a + b # 四則演算 OK (要素毎の演算) [2.0, 1.0, 1.0, 0.0]

d = NArray.int(4).indgen # [0, 1, 2, 3]

http://ruby.gfd-dennou.org/index-j.htm

オブジェクト指向スクリプト言語 Ruby を, 地球物理学におけるデータ解析, 可視化, 数値シミュレーションに使うための, ボランティアベースのゆるい括りのプロジェクト

いろいろなソフトウェアを作り提供している.

http://rubyonrails.org/

Ruby on Rails(ルビーオンレイルズ)はオープンソースのWebアプリケーションフレームワークである。RoRまたは単にRailsと呼ばれる。その名にも示されているようにRubyで書かれている。またModel View Controller(MVC)アーキテクチャに基づいて構築されている。

実アプリケーションの開発を他のフレームワークより少ないコードで簡単に開発できるよう考慮し設計されている (wikipedia)

http://www.gfd-dennou.org/library/davis/gfdnavi/

Gfdnavi は地球流体データのデータベース、解析、可視化のためのデスクトッ プツール兼サーバーです。Gfdnavi を使うとデータ公開や共有のためのサーバー が簡単に立ち上げられます。公開用ディレクトリーをスキャンして、データファ イルを自動認識しメタデータデータを抽出して登録します。利用者はWebブラ ウザーでアクセスし、Webベースで解析・可視化も行えます。他人に提供しな い場合でも、個人が自分自身のデータ整理に手軽に使え、Webブラウザーを通 して解析・可視化できます。その結果得られた画像や数値データをデータベー スに保存することもできます。

まとめ

おしまい

あっ そうそう

このプレゼンソフトの話

もちろん Ruby で

.... はありません orz

興味がある人は

prezi.com

A Programmer's Best Friend, Ruby

そういう話はプレゼンが終わった後にしましょうね

神戸大学理学研究科 / 惑星科学研究センター

西澤誠也

Rubys

Ruby

いままでありがとう

Perl

Fortran, C での普通のプログラミング

Fortran

PHP

C/C++

Ruby

オブジェクト指向プログラミング

http://www.ruby-lang.org/

Java

おさらば

Ruby とは

(www.ruby-lang.org より)

Ruby コードサンプル (住所を調べる)

Ruby コードサンプル (数学演算だって)

Rubyは、手軽なオブジェクト指向プログラミングを実現するための種々の機能を持つオブジェクト指向スクリプト言語です。本格的なオブジェクト指向言語であるSmalltalk、EiffelやC++などでは大げさに思われるような領域でのオブジェクト指向プログラミングを支援することを目的としています。もちろん通常の手続き型のプログラミングも可能です。

Rubyはテキスト処理関係の能力などに優れ、Perlと同じくらい強力です。さらにシンプルな文法と、例外処理やイテレータなどの機構によって、より分かりやすいプログラミングが出来ます。

まあ、簡単にいえばPerlのような手軽さで「楽しく」オブジェクト指向しようという言語です。どうぞ使ってみてください。

Rubyはまつもと ゆきひろが個人で開発しているフリーソフトウェアです。

Ruby on Rails

Ruby コードサンプル (制御構文)

1.9 (YARV)

JRuby

拡張ライブラリ

電脳Rubyプロジェクト

Basic

  • Misc - Miscellaneous functions and classes to help Ruby programming. To be used in other NumRu libraries.
  • Units - Class to handle units of physical quantities

Gfdnavi

  • Ruby/Msise90 - Ruby wrapper of the MSISE-90 neutral atmosphere empirical model from the surface to lower exosphere.
  • Met - a collection of meteorological apprications (functions, graphics, etc.)

Geophysica Application

Graphics

  • RubyDCL - one-to-one interface to the DCL graphic library
  • VTK-Ruby - a patch of a one-to-one interface to the Visualization ToolKit (VTK), a 3D graphic library and GUI toolkit.
  • EasyVTK - a upper methods for Ruby-VTK to use easily.
  • Ruby-LibFAME - a wrapper of libFAME, which is a library for fast MPEG video encoding.
  • gave - Gtk+ based grid data analyser and viewer. Supports 1D & 2D plots, animations, etc.

GUI

File IO

Numerical Comptation

  • RubyNetCDF - the ruby interface to the NetCDF library:
  • GrADS_Gridded (included in GPhys) - handles the GrADS gridded data format.
  • Grib (included in GPhys) - handles the Grib data format.
  • Ruby-HDFEOS5 - a ruby interface to the HDF-EOS5 library.
  • Ruby-NuSDaS - handles the NuSDaS data format.
  • GPV - handles Grid Point Value (GPV) data made by Japan Meteorological Agency (JMA, or Kishou-cho).
  • gt3nc - converts GTOOL3 data into NetCDF.
  • Ruby-SSL2 - a wrapper of SSL2 (Scientific Subroutine Library) made by Fujitsu.
  • Ruby-LAPACK - a wrapper of LAPACK.
  • Ruby-FFTW3 - Fast Fourier Transforms by using FFTW Ver.3.
  • Ruby-ISPACK - a wrapper of ISPACK (Fortran library for GFD computation).
  • Ruby-SPML - a wrapper of SPML (SPMODEL library)

Arrays

Data handling

  • NArrayMiss - Multi-dimensional Array class with missing data handling using NArray.
  • Multibitnums - a C extention library for integers with arbitrary bit lengths.
  • GPhys - comprehensive library for self-descriptive gridded physical data (in NetCDF, GrADS, or on memory) with graphics
  • gphys-remote - a suite of GPhys directory services using dRuby