開発環境
- 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 10(More Fun with Ruby)Review Questions 3を解いてみる。
その他参考書籍
- 『プログラミング言語 Ruby』David Flanagan, まつもと ゆきひろ 著 、卜部 昌平 監訳、長尾 高弘 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-394-4)
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 コメント:
コメントを投稿