2012年7月27日金曜日

開発環境

『Learning Ruby』(Michael Fitzgerald 著、O'Reilly Media、2007年、ISBN978-0-596-52986-4)の Chapter 9(Classes)Review Questions 7を解いてみる。

その他参考書籍

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 コメント:

コメントを投稿