開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Ruby
『Learning Ruby』(Michael Fitzgerald 著、O'Reilly Media、2007年、ISBN978-0-596-52986-4)の Chapter 9(Classes)Review Questions 7を解いてみる。
その他参考書籍
- 『プログラミング言語 Ruby』David Flanagan, まつもと ゆきひろ 著 、卜部 昌平 監訳、長尾 高弘 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-394-4)
7.
継承できるクラスが1つか複数化の違い。rubyは多重継承不可。(C#も不可。pythonは多重継承可能。)
コード(TextWrangler)
#!/usr/bin/env ruby # -*- coding: utf-8 -*- class Base def p puts "Hello, World!" end def f puts "Hello, Ruby!" end end class Derived < Base def f puts "Hello, Python!" end end a = Base.new b = Derived.new [a,b].each do |c| c.p c.f end
入出力結果(Terminal)
$ ./sample.rb Hello, World! Hello, Ruby! Hello, World! Hello, Python! $
0 コメント:
コメントを投稿