×Ô¶¯»¯²âÊÔ֮·£¨Èý£© rubyÀïµÄgetÓëset·½·¨
ÕÕÀý¿ÉÒÔÏÈ¿´¶Ë³ÌÐò
class Person
def initialize( name,age=18 )
@name = name
@age = age
@motherland = "China"
end
def talk
puts "my name is "+@name+", age is "+@age.to_s
if @motherland == "China"
puts "I\'m Chinese."
else
puts "I\'m foreigner."
end
end
attr_writer :motherland
end
p1=Person.new("kaichuan",20)
p1.talk
p2=Person.new("Ben")
p2.motherland="ABC"
p2.talk
³ÌÐòÔËÐнá¹û
my name is kaichuan, age is 20
I'm Chinese.
my name is Ben, age is 18
I'm foreigner.
>Exit code: 0
ÓйýÃæÏò¶ÔÏó±à³ÌÓïÑÔ¾ÀúµÄͯЬºÜÈÝÒ׿ÉÒÔ¿´Ã÷°×£¬µ«ÊÇÀïÃæÖµµÄÒ»ÌáµÄÊÇÕâ¾ä£º“attr_writer :motherland”
Õâ¾ä»°Ï൱ÓÚÎÒÃÇÃæÏò¶ÔÏó±à³ÌÓïÑÔµÄset·½·¨£¬Ò²¿ÉÒÔÕâÑùд
def motherland=(value)
return @motherland =value
end
ÄÇôÏàÓ¦µÄget·½·¨Îª attr_ reader :motherland
Ï൱ÓÚ
def motherland
return @motherland
end
ÏàÓ¦µÄ attr_accessor :motherland Ï൱ÓÚattr_reader:motherland£» attr_writer :motherland
Ïà¹ØÎĵµ£º
×î½üÔÚ¿´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 ......
Ruby 101£º¶¯Ì¬±à³Ì
Written by Allen Lee
µ±method_missingµÄħ·¨Ê§Ð§Ê±……
ÔÚÉÏһƪÎÄÕÂÀÎÒÃÇͨ¹ýÖØÐ´HashÀàµÄmethod_missing·½·¨°ÑHash¶ÔÏóÄ£Äâ³ÉÄäÃû¶ÔÏ󣬵«ÊÇ£¬ÕâÖÖ×ö·¨ÓÐʱ»á²úÉúһЩĪÃûÆäÃîµÄÎÊÌ⣬¾Ù¸öÀý×Ó°É£¬¼ÙÈçÎÒ°Ñprocess·½·¨£¨ÍêÕûʵÏֲμûÉÏһƪÎÄÕ ......
require 'win32ole'
excel = WIN32OLE::new('excel.Application')
workbook = excel.Workbooks.Open('E:\RubyApp\bmk.xls')
worksheet = workbook.Worksheets(1) #get hold of the first worksheet
worksheet.Select #bring it to the front -need sometimes to run macros, not for working with a worksheet from ru ......
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
......