<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IT公司面试手册 &#187; Ruby</title>
	<atom:link href="http://www.mianwww.com/html/category/it-interview/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mianwww.com</link>
	<description></description>
	<lastBuildDate>Wed, 08 Feb 2012 11:48:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>介绍一下Ruby的特点</title>
		<link>http://www.mianwww.com/html/2011/05/9253.html</link>
		<comments>http://www.mianwww.com/html/2011/05/9253.html#comments</comments>
		<pubDate>Fri, 27 May 2011 15:27:12 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=9253</guid>
		<description><![CDATA[Ruby是一种功能强大的面向对象的脚本语言，可以使用它方便快捷地进行面向对象程序设计。与Perl类似，而且Ruby具有强大的文本处理功能，使文本处理变得简单。此外还可以方便地使用C语言来扩展Ruby的功能。 若您曾经“想要一种简单的面向对象的语言”，或者认为“Perl的功能虽然好用，但它的语法真让人受不了”，又或者觉得“LISP系列语言的思想不错，但到处都是括号真让人讨厌，最起码算式应该按照通常的样式书写”。那么，Ruby或许能让您满意。 归纳起来，Ruby有以下优点：  解释型执行，方便快捷 Ruby是解释型语言，其程序无需编译即可执行。  语法简单、优雅 语法比较简单，类似Algol系语法。  完全面向对象 Ruby从一开始就被设计成纯粹的面向对象语言，因此所有东西都是对象，例如整数等基本数据类型。  内置正则式引擎，适合文本处理 Ruby支持功能强大的字符串操作和正则表达式检索功能，可以方便的对字符串进行处理。  自动垃圾收集 具有垃圾回收（Garbage Collect，GC）功能，能自动回收不再使用的对象。不需要用户对内存进行管理。  跨平台和高度可移植性 Ruby支持多种平台，在Windows, Unix, Linux, MacOS上都可以运行。Ruby程序的可移植性非常好，绝大多数程序可以不加修改的在各种平台上加以运行。  有优雅、完善的异常处理机制 Ruby提供了一整套异常处理机制，可以方便优雅地处理代码处理出错的情况。  拥有很多高级特性 Ruby拥有很多高级特性，例如操作符重载、Mix-ins、特殊方法等等，是用这些特性可以方便地完成各种强大的功能。 同时，由于是解释型语言，Ruby也有下列缺点：  解释型语言，所以速度较慢  静态检查比较少]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2011/05/9253.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby如何实现动态方法调用？</title>
		<link>http://www.mianwww.com/html/2009/11/6448.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6448.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:47:44 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6448</guid>
		<description><![CDATA[在Ruby中，有多种方法可以实现方法的动态调用。 1. 使用send方法 第一种实现动态方法调用是使用send方法，send方法在Object类中定义，方法的第一个参数是一个符号用来表示所要调用的方法，后面则是所调用方法需要的参数。 &#8220;This is a dog1&#8243;.send(:length) =&#62; 14 上面的代码中通过send方法去对一个字符串执行length操作，返回字符串的长度。 class TestClass  def hello(*args)   &#8221;Hello &#8221; + args.join(&#8216; &#8216;)  end end a = TestClass.new puts a.send :hello, &#8220;This&#8221;, &#8220;is&#8221;, &#8220;a&#8221;, &#8220;dog!&#8221; 执行结果为： Hello This is a dog! 2. 使用Method类和UnboundMethod类 另一种实现动态方法调用是使用Object类的method方法，这个方法返回一个Method类的对象。我们可以使用call方法来执行方法调用。 test1 = &#8220;This is a dog1&#8243;.method(:length) test1.call  =&#62; 14 class Test  def initialize(var)   @var = var [...]]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6448.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby如何进行文件操作？ 请用代码表示</title>
		<link>http://www.mianwww.com/html/2009/11/6446.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6446.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:45:08 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6446</guid>
		<description><![CDATA[Ruby使用File类来操作文件，可以通过File.new来创建一个File类的实例并打开这个文件。 file = File.new(&#8220;testfile&#8221;, &#8220;r&#8221;) # &#8230; process the file file.close testfile是想要操作的文件名，”r”说明了文件的操作模式为读取。可以使用”w”表示写入，”rw”表示读写。 最后要记得关闭打开的文件，确保所有被缓冲的数据被写入文件，所有相关的资源被释放。 也可以使用File.open来打开文件，open和new的不同是open可以使用其后的代码块而new方法则返回一个File类的实例。 File.open(&#8220;testfile&#8221;, &#8220;r&#8221;) do &#124;file&#124; # &#8230; process the file end open操作的另一个优点是处理了异常，如果处理一个文件发生错误抛出了 异常的话，那么open操作会自动关闭这个文件，下面是open操作的大致实现： class File def File.open(*args) result = f = File.new(*args) if block_given? begin result = yield f ensure f.close end end return result end end  对于文件的路径，Ruby会在不同的操作系统间作转换。例如，在Windows下，/ruby/sample/test.rb会被转化为\ruby\sample\test.rb。当你使用字符串表示一个Windows下的文件时，请记住使用反斜线先转义：  “c:\\ruby\\sample\\test.rb” 也可以使用File::SEPARATOR表示不同系操作统的路径分割符。]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6446.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby如何创建一个线程？</title>
		<link>http://www.mianwww.com/html/2009/11/6443.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6443.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:41:45 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6443</guid>
		<description><![CDATA[可以使用Thread.new方法去创建一个线程，可以随后代码块中列出线程执行的代码： x = Thread.new { sleep 0.1; print &#8220;x&#8221;; print &#8220;y&#8221;; print &#8220;z&#8221; } a = Thread.new { print &#8220;a&#8221;; print &#8220;b&#8221;; sleep 0.2; print &#8220;c&#8221; } 执行结果为： ab 上面的示例程序中使用Thread.new创建了二个线程，线程随即开始运行。但是运行结果很奇怪，为什么程序运行结果是“ab”呢？我们预期的执行结果应该是 “abxyzc”。 当Ruby程序执行完毕的时候，他会杀掉所有的线程，不管其它的线程的运行状态如何。如果没有使用join方法，那么主程序执行完毕后会把所有没有执行完毕的线程杀掉。 上面的实例程序中，当主程序运行完毕时，两个线程都没有运行结束就被中止掉了。我们可以使用join方法来让主程序等待某个特定线程结束，对每一个线程使用join方法，可以确保在程序结束前所有的线程可以运行完毕。 x = Thread.new { sleep 0.1; print &#8220;x&#8221;; print &#8220;y&#8221;; print &#8220;z&#8221; } a = Thread.new { print &#8220;a&#8221;; print &#8220;b&#8221;; sleep [...]]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6443.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>介绍一下Ruby的多线程处理</title>
		<link>http://www.mianwww.com/html/2009/11/6441.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6441.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:40:44 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6441</guid>
		<description><![CDATA[Ruby的多线程是用户级多线程，这样使得Ruby的多线程移植非常容易，你并不需关心具体的操作系统；这样做也使线程容易控制，程序不容易产生死锁这类严重的线程问题。 但是同时，由于Ruby的多线程并不是真正意义上的操作系统级多线程，不管代码使用了多少个Thread类的实例，都只会在启动解释器这一个进程内执行，由Ruby解释器进行具体的线程切换管理，其效率要低于由操作系统管理线程的效率，且不能使用多个CPU。 在Ruby中同时做多件事最简单的方式就是使用Thread类，Thread类提供了一种高效和轻量级的手段来同时处理多件任务。 Thread类由Ruby解释器具体实现，提供了一种同时处理多个任务的方法， Thread类实现的并不是操作系统级多线程。 Ruby多线程的优点和缺点同样明显，缺点是效率不如操作系统级多线程，不能使用多个CPU，但其优点也很明显，即可移植性很高。这就需要设计人员综合考虑。]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6441.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>既然说Ruby中一切都是对象，那么Ruby中类也是对象吗？</title>
		<link>http://www.mianwww.com/html/2009/11/6439.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6439.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:33:06 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6439</guid>
		<description><![CDATA[没错，类也是对象，这是Ruby和C++/Java的一个显著不同，在C++/Java中，类仅仅是一个数据抽象，并没有类也是对象这样的概念。而在Ruby中存在着元类的概念，类也是对象，所有类都是元类的实例对象。和C++/Java相比，Ruby的面向对象程度更高。 可以看到，类对象和实例对象一样有自己的ojbect_id，你可以象调用一个实例对象的方法一样去用它去调用类方法。所有类对象的类是Class类，Oject类是所有类的基类。 irb(main):003:0&#62; Object.class =&#62; Class irb(main):004:0&#62; Object.superclass =&#62; nil]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6439.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby中的保护方法和私有方法与一般面向对象程序设计语言的一样吗？</title>
		<link>http://www.mianwww.com/html/2009/11/6437.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6437.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:31:45 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6437</guid>
		<description><![CDATA[Ruby中的保护方法和私有方法与一般面向对象程序设计语言的概念有所区别，保护方法的意思是方法只能方法只能被定义这个方法的类自己的对象和子类的对象访问，私有方法只能被对象自己访问。 class Test  def method1    #默认为公有方法  …  end  protected  #保护方法  def method2  …  end    private  #私有方法  def method3  end  public   def test_protected(arg) #arg是Test类的对象   arg.method2   #正确，可以访问同类其他对象的保护方法  end  def test_private(arg) #arg是Test类的对象   arg.method3  #错误，不能访问同类其他对象的私有方法  end end obj1 = Test.new obj2 = Test.new    obj1.test_protected(obj2) obj1.test_private(obj2)  可以看到，和C++/Java相比，Ruby提供了更好的封装性。]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6437.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解释一下ruby中的特殊方法与特殊类？</title>
		<link>http://www.mianwww.com/html/2009/11/6435.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6435.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:29:21 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6435</guid>
		<description><![CDATA[特殊方法是指某实例所特有的方法。一个对象有哪些行为由对向所属的类决定，但是有时候，一些特殊的对象有何其他对象不一样的行为，在多数程序设计语言中，例如C++和Java，我们必须定义一个新类，但在Ruby中，我们可以定义只从属于某个特定对象的方法，这种方法我们成为特殊方法(Singleton Method)。 class SingletonTest   def info    puts &#8220;This is This is SingletonTest method&#8221;   end end obj1 = SingletonTest.new obj2 = SingletonTest.new def obj2.info   puts &#8220;This is obj2&#8243; end obj1.info obj2.info  执行结果为： This is This is SingletonTest method This is obj2 有时候，我们需要给一个对象定义一系列的特殊方法，如果按照前面的方法，那么只能一个一个定义： def obj2.singleton_method1 end def obj2.singleton_method2 end def obj2.singleton_method3 end …… def obj2.singleton_methodn end 这样做非常繁复麻烦，而且无法给出一个统一的概念模型，因此Ruby提供了另外一种方法， [...]]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6435.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ruby如何进行集成操作？Ruby能进行多重继承吗？</title>
		<link>http://www.mianwww.com/html/2009/11/6433.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6433.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:28:12 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6433</guid>
		<description><![CDATA[Ruby继承的语法很简单，使用 &#60; 即可。 Ruby语言只支持单继承，每一个类都只能有一个直接父类。这样避免了多继承的复杂度。但同时，Ruby提供了mixin的机制可以用来实现多继承。 可以使用super关键字调用对象父类的方法，当super省略参数时，将使用当前方法的参数来进行调用。]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6433.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>介绍一下Ruby中的对象，属性和方法</title>
		<link>http://www.mianwww.com/html/2009/11/6431.html</link>
		<comments>http://www.mianwww.com/html/2009/11/6431.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:26:29 +0000</pubDate>
		<dc:creator>jim.jin</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.mianwww.com/?p=6431</guid>
		<description><![CDATA[在Ruby中，除去内部类的对象以外，通常对象的构造都是动态确定的。某对象的性质由其内部定义的方法所决定。 看下面的例子，我们使用new方法构造一个新的对象， class Person def initialize(name, gender, age)  @name = name  @gender = gender @age = age end end  people = Person.new(&#8216;Tom&#8217;, &#8216;male&#8217;, 15) 我们可以使用Person.new方法来创建一个Person类的实例对象。以@打头的变量是实例变量，他们从属于某一实例对象，Ruby中实例变量的命名规则是变量名以@开始，您只能在方法内部使用它。 initialize方法使对象变为“就绪”状态，initialize方法是一个特殊的方法，这个方法在构造实例对象时会被自动调用。 对实例进行初始化操作时，需要重定义initialize方法。类方法new的默认的行为就是对新生成的实例执行initialize方法，传给new方法的参数会被原封不动地传给initialize方法。另外，若带块调用时，该块会被传给initialize方法。因此，不必对new方法进行重定义。 在Ruby中，只有方法可以操作实例变量，因此可以说Ruby中的封装是强制性的。在对象外部不可以直接访问，只能通过接口方法访问。 class Person   def name    @name   end   def gender    @gender   end   def age    @age   end end people = Person.new(&#8216;Tom&#8217;, &#8216;male&#8217;, 15) puts people.name puts people.gender puts people.age 输出结果为： [...]]]></description>
		<wfw:commentRss>http://www.mianwww.com/html/2009/11/6431.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

