2012年8月5日日曜日

開発環境

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

その他参考書籍

3.

継承したクラス名(親クラス)を返す。

コード(TextWrangler)

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

class Base
  def f
    puts "Hello, Ruby!"
  end
end

class Derived < Base
  def g
    puts "Hello, World!"
  end
end

a = Base.new
b = Derived.new
a.f
b.f
b.g
[Base, Derived,Integer,String,Array,Hash].each do |item|
  puts item.superclass
end

入出力結果(Terminal)

$ ./sample.rb
Hello, Ruby!
Hello, Ruby!
Hello, World!
Object
Base
Numeric
Object
Object
Object
$

0 コメント:

コメントを投稿