试了试mixmi功能

发表时间:2007年5月6日 1时14分24秒 评论/阅读(0/0)
嗯.书太厚了点,看到了第十章.想动动手了.
动态语言的特性真是丰富.我们可以做的事情太多了.哈哈!!


module Debug
def who_am_i
"#{self.class.name} (\##{self.object_id}): #{self.to_s}"
end
end
class Object
def self.inherited(subclass)
puts "New subclass: #{subclass}"
end
end
class Phonograph
include Debug
def to_s
" I'm Phonograph"
end
end
class EightTrack

include Debug
include Enumerable
def to_s
" I'm EightTrack"
end

def each
yield 1
yield 2
yield 3
end
end

ph = Phonograph.new
et = EightTrack.new
puts(ph.who_am_i)
puts(et.who_am_i)
et.each {|x| puts x}
puts et.select{|x| x > 1}
puts et.include?(1)
puts et.inject{|x,y| x*y}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值