Ruby的装饰器模式实现
class Tree
def initialize
puts "Make a normal tree"
end
def decorate
puts "Make sure the tree won\'t fall"
end
end
class RedBalls < Tree
def initialize(tree)
@parent = tree;
end
def decorate
@parent.decorate
puts "Put on some red balls"
end
end
class BlueBalls < Tree
def initialize(tree)
@parent = tree;
end
def decorate
@parent.decorate
puts "Add blue balls"
end
end
class Angel < Tree
def initialize(tree)
@parent = tree;
end
def decorate
@parent.decorate
puts "An angel on the top"
end
end
tree = Angel.new(BlueBalls.new(RedBalls.new(Tree.new)))
tree.decorate
相关文档:
最近在看John E.Hopcroft,Rajeev Motwani,Jeffrey D.Ullman 三巨头写的Introduction to Automata Theory,Language,and Computation,想写一个Turing 机验证一下自己写的状态转移函数对不对。懒得很,网上搜了几个不错的。但Ruby Quiz 上的这个最简单。
162 Turing 机
问题描述
Quiz
description by James Edward Gray ......
订单处置,首先要有一个订单的详细列表(包括数量,价钱啥的)和一个对于个人的一些信息的一个表。因而我们创造两个模型,line_item(列表项),order(列表),其后编者如次
/db/migrate xxx_create_order xxx_line_item
Ruby代码
一.class CreateOrders < ActiveRecord::Migration
二.def self.up
3. create_tabl ......
ruby on rails安装mysql数据库
1. 下载mysql软件
http://www.mysql.cn/
mysql中文官方网站下载安装软件,选择5.0
2. 安装mysql,设置默认字符集为utf-8
3. 下载mysql for ruby的驱动并安装
http://rubyforge.org/搜索mysql,找到mysql -win
点击下载,进入页面
http://rubyforge.org/frs/?group_id= ......
1.install ruby
download from http://www.ruby-lang.org/en/news/2009/12/07/ruby-1-9-1-p376-is-released/
2.install rails
ruby gem install rails --include-dependencies
3.install mysql
download from http://sourceforge.net
ruby gem install&nb ......
松本行宏如约于圣诞节发布了Ruby 1.9。根据Ruby的惯例,小数点后面第一位如果是单数,那么就表明这是一个实验版本,不推荐用于产品环境。所谓“产品环境”,对于目前的Ruby来说,基本上就是Ruby on Rails。从目前RoR社群的反映来看,确实有人正在尝试用Ruby 1.9配合RoR,但是尚属 ......