2012年7月26日木曜日

開発環境

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

その他参考書籍

6.

No.モジュールはクラスでincludeで使用。(違うモジュールにあるときはさらにそのモジュールをrequireで使用。)

コード(TextWrangler)

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

module Sample
  def p
    puts 'Hello, Ruby!'
  end
end

class C
  include Sample
end

c = C.new
c.p

入出力結果(Terminal)

$ ./sample.rb
Hello, Ruby!
$

0 コメント:

コメントを投稿