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
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
- vim config/environment.rb
- vim app/controllers/application.rb
- vim Rakefile
- rake updatepo
- (make po files from the .pot file)
- rake makemo
require 'gettext/rails' ....
Ujihisa-san’s slides on SlideShare
Rails service
PatchService – http://www.patchservice.net/