Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Éè¼Æģʽ ¹Û²ìÕßģʽʵÏÖÀý×Ó(ruby)

rubyÖÐ×Ô´øʵÏÖ¹Û²ìÕßģʽµÄÀàobserver¡£¿ÉÒÔÀûÓÃËüÀ´ÊµÏÖ¹Û²ìÕßģʽ¡£
´úÂëÀý×Ó£º
# -*- coding: GB2312 -*-
require 'observer'
# ¹Û²ìÕßģʽ(ruby)µÄʹÓÃÀý×Ó
# ±»¹Û²ìÕßP
class PObservable
include Observable
end
# ¹Û²ìÕßA
class AObserver
# update·½·¨ÃûÊDZØÐëµÄÒªÓеÄ
def update(arg)
puts "AObserver ±»Í¨ÖªÁË " + arg
end
end
# ¹Û²ìÕßB
class BObserver
# update·½·¨ÃûÊDZØÐëµÄÒªÓеÄ
def update(arg)
puts "BObserver ±»Í¨ÖªÁË " + arg
end
end
# ¹Û²ìÕß³õʼ»¯
observer_a = AObserver.new
observer_b = BObserver.new
# ±»¹Û²ìÕß³õʼ»¯
obj = PObservable.new
# Ìí¼Ó¼àÊÓ¶ÔÏó
obj.add_observer(observer_a)
obj.add_observer(observer_b)
# ±»¹Û²ìÕ߸ıäÁË ->Õâ¶Î´úÂë ±ØÐëÓÐ ²»È»ÎÞ·¨Í¨Öªµ½¹Û²ìÕß
obj.changed
# ֪ͨ¹Û²ìÕß
obj.notify_observers("Test")

Êä³ö½á¹û£º
AObserver ±»Í¨ÖªÁË Test
BObserver ±»Í¨ÖªÁË Test


Ïà¹ØÎĵµ£º

ruby c++

While looking for information on the subject, I looked into the ONLamp article Extending Ruby with C by Garrett Rooney, the Extending Ruby chapter in the Pickaxe, README.EXT (located at /usr/share/doc/ruby1.8-dev/README.EXT.gz on my Ubuntu system) and got some help from Kjetil.
The resulting file c ......

ruby on rails(10) ´¦Àí¶©µ¥

¶©µ¥´¦Öã¬Ê×ÏÈÒªÓÐÒ»¸ö¶©µ¥µÄÏêϸÁÐ±í£¨°üÀ¨ÊýÁ¿£¬¼ÛǮɶµÄ£©ºÍÒ»¸ö¶ÔÓÚ¸öÈ˵ÄһЩÐÅÏ¢µÄÒ»¸ö±í¡£Òò¶øÎÒÃÇ´´ÔìÁ½¸öÄ£ÐÍ£¬line_item(ÁбíÏî),order(Áбí)£¬Æäºó±àÕßÈç´Î
/db/migrate xxx_create_order xxx_line_item
Ruby´úÂë
Ò».class CreateOrders < ActiveRecord::Migration
¶þ.def self.up
3. create_tabl ......

C++0x³¢ÏÊ ÓÃlambda±í´ïʽģÄâRubyµÄ¹ý³Ì¶ÔÏó

¹ØÓÚC++0x
Ô¤¼ÆÓÚÃ÷Äêµ×ÍƳöµÄбê×¼C++0x£¬Ëä˵ÒѽӽüÊչٽ׶Σ¬È´ÈÔÓÐÈô¸ÉÓдý½ÓÄɵÄÐÂÌá°¸±»Ìá³ö¡£ÓÈÆäÖµµÃ¹Ø×¢µÄÊÇ£¬Óëlambda±í´ïʽÒÔ¼°¾Ö²¿º¯ÊýÏà¹ØµÄÌá°¸“Unified Function Syntax£¨Í³Ò»µÄº¯ÊýÓï·¨£©”£¬¾¡¹Ü²»Êܱê׼ίԱ»á´ý¼û£¨Á½Äê¼äÀú¾­ËÄ´ÎÑÓ³Ù±í¾ö£¬Á½´Î²»Óèͨ¹ý£©£¬ÈÔÈ»“ÍçÇ¿µØ”ÍƳöÁ ......

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 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ