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
相关文档:
有些同学提问:我写数据到文件中会把老的数据替换掉。
怎么在源文件的基础上添加内容,而不是重写
【ruby code】
def txt_write(value,memo)
File.open("c:\\my_text.txt", 'a') do |f|
......
上一篇文章
说了Ruby的安装和运行,也简单的说了下类和对象。这里主要谈谈变量的问题。
先说常量
。如果变量名以大写字母开头,就被视为常量,但通常是所有字母都大写。但和其他语言不同,在Ruby中,你仍然可以改变常量的值,当然解释器会抛出一个警告:
#! /usr/bin/ruby
CONSTANT = 1
print "#{CONSTANT}\n&qu ......
订单处置,首先要有一个订单的详细列表(包括数量,价钱啥的)和一个对于个人的一些信息的一个表。因而我们创造两个模型,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的工作,我应该知道哪些知识
?
还好,我并不是想指点你什么,只是想按我的思维方式展开,让你能"闻"到点东西即成.
古云:知己知彼,百战不殆;不知彼而知己,一胜一负; ......
松本行宏如约于圣诞节发布了Ruby 1.9。根据Ruby的惯例,小数点后面第一位如果是单数,那么就表明这是一个实验版本,不推荐用于产品环境。所谓“产品环境”,对于目前的Ruby来说,基本上就是Ruby on Rails。从目前RoR社群的反映来看,确实有人正在尝试用Ruby 1.9配合RoR,但是尚属 ......