sign in
Home | Updates | Pages | Users | Admin | Help

ruby18hirakata

18th Ruby/Rails Meeting – Hirakata

What is Ruby

  • Everything is Object.
  • Open Class – you can extend every class
  • Block – do … end (or { ... } )
  • Useful classes:
    • Numeric, String, Symbol, Array, Hash, Regexp, Range

Class and Instance

link_to('',{:page => 2})
link_to '', {:page => 2}
link_to '', :page => 2

Rails

  • CoC (Convention over Configuration)
  • DRY (Don’t Repeat Yourself)

Sample application – BBS

$ rails -d sqlite3 bbs && cd bbs
$ script/generate model Comment
%% edit app/models/comment.rb
%% edit db/migrate/001_create_comments.rb
$ rake db:migrate

better use scaffold_resource , it will create model, controller and the migration

The Ruby “Saho”

how to look “beautiful”. “busaho” – mazui ;)

Basics

  • object
  • block
  • duck typing
  • metaprogramming

“Busaho”

  • The code is not gentle for the programmer
  • overloading (in C++ and Java it’s usual)
  • creating classes just for the classes themself (overwork)
  • just copy-paste from some design patterns
  • difficult method names
  • eval() is not the evil, it’s the LAST weapon

what to use for binary data – pack() and unpack() ? pack library?

Game programming with Ruby – MyGame library

Dan-san, dGames, http://dgames.jp/dan/

There is a book – “starting game programming with ruby” + CD

Concepts

  • SDL-based (Ruby/SDL)short code (multiplatform)
  • everything is object (character, blocks, tree, sky etc.)
  • designed for begginers
  • to be easy and “tanoshii” ;)

Install

  • SDL
  • Ruby
  • Ruby/SDL
  • MyGame
For Windows: ActiveScriptRuby, download and install Ruby/SDL
install_mygame.rb

Other: mygame-0.9.1.tar.gz

Usage

  • Bootstrap – (require ’’)
  • Main loop – block (do..end), 60 times per sec (60Hz)
    • clear screan
    • wait()
    • create object (render)
    • display object
  • Using display object
  • Keys
    • key_pressed?()
    • new_key_pressed?()

Sample

require 'mygame/boot'
Image.render 'sample.png', :x => 100, :y => 100
Image.render 'sample.png', :x => 100, :y => 200

image = Image.new('sample.png')
image.x = 50
image.y = 100
image.scale = 2.0
image.angle = 90
image.alpha = 128
image.render

counter = 0
main_loop do
  image.render
  image.x += 1       # moving the object (sliding)
  image.angle += 8   # rotation

  # using keys
  image.x += 8 if key_pressed?(Key::RIGHT)
  image.x -= 8 if key_pressed?(Key::LEFT)
  image.y += 8 if key_pressed?(Key::DOWN)
  image.y -= 8 if key_pressed?(Key::UP)

  counter += 1 if new_key_pressed?(Key::SPACE)
  Font.render(counter)
end

Internationalization in Ruby

Ruby-GetText-Package

8 steps in internationalization

application → .pot file → ja, pl → .mo

  1. vim config/environment.rb
  2. vim app/controllers/application.rb
  3. vim Rakefile
  4. rake updatepo
  5. (make po files from the .pot file)
  6. rake makemo
require 'gettext/rails'
....

Ujihisa-san’s slides on SlideShare

Rails service

PatchService – http://www.patchservice.net/


Powered by JunebugWiki v0.0.31 Page last edited by stoyan on August 15, 2007 12:34 PM (diff)
[readonly] Version 2 (current) «olderversions