tips_etc_020 - spoolkitamura/nyle-doc-jp GitHub Wiki
メソッドで「Nyle.」修飾子を省くには?
Screenクラスの中で、Nyleのモジュールを includeすると
Nyleモジュール内のメソッドを呼び出す際に Nyle.の修飾子を
省くことができるようになります。
下記の2つのプログラムはどちらも同じ動作になります。
わかりやすい方のスタイルでプログラムを記述してください。
Nyleモジュールをincludeしない場合
require 'nyle'
class Screen < Nyle::Screen
def initialize
super(240, 240, {bgcolor: :IVORY})
end
def draw
Nyle.draw_rect(50, 50, 140, 140, {color: :ORANGE, fill: true})
Nyle.draw_rect(50, 50, 140, 140, {color: :RED, weight: 5})
end
end
Screen.new.show_all
Nyle.main
[実行結果]
![]() |
|---|
Nyleモジュールをincludeする場合
require 'nyle'
class Screen < Nyle::Screen
include Nyle
def initialize
super(240, 240, {bgcolor: :IVORY})
end
def draw
draw_rect(50, 50, 140, 140, {color: :ORANGE, fill: true}) # Nyle. の修飾子が不要
draw_rect(50, 50, 140, 140, {color: :RED, weight: 5}) # Nyle. の修飾子が不要
end
end
Screen.new.show_all
Nyle.main
[実行結果]
![]() |
|---|
