Monday, February 16, 2009

Design Patterns in Ruby

Previously I wrote a post about Design Patterns in Beanshell. Now I have converted them in ruby scripts. Some of DP implementations in Ruby does not make sense because of highly dynamic nature of this language.

Creational Patterns

Abstract Factory
Builder
Factory Method
Prototype
Singleton
Singleton (corrected)
Lazy Initialization

Structural Patterns

Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy

Behavioral Patterns

Chain of Responsibility
Command
Domain Function
Interpreter
Iterator
Mediator
Memento
Observer
Observer with Observer library
State
Strategy
Template Method
Template Method (corrected)
Visitor

Enterprise Patterns

MVC
Data Access Object
Map-Reduce

My main sources:

1. Design Patterns in Beanshell
2. Design Patterns in Ruby : web site and the book

Use Google Translate from command line (Ruby)

If you have Ruby/Gem installed on your computer, you can start using Google Translate from the command line. Just follow these instructions:

$ gem sources -a http://gems.github.com
$ gem install google-translate


Now you have "translate" command available:

$ translate list

- displays the list of supported languages

$ translate detect "hello world"

- detects language of text

$ translate en:ru "hello world"
$ translate en:ru hello world


- translates from English to Russian

$ translate ru "hello world"
$ translate ru hello world


- translated from auto-detected language to Russian.