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
[実行結果]
![]() |
---|