class Bitmap alias :draw_text2 :draw_text unless defined? :draw_text2 def draw_text(*args) case args.size when 2 rect = args[0] text = args[1].split("\n") align = 0 when 3 rect = args[0] text = args[1].split("\n") align = args[2]%3 when 5 rect = Rect.new(*(args[0,4])) text = args[4].split("\n") align = 0 when 6 rect = Rect.new(*(args[0,4])) text = args[4].split("\n") align = args[5]%3 else raise ArgumentError,"错误的参数个数(#{args.size} to 2,3,5,6)." end return if text.empty? wmax = [text.map{|t| self.text_size(t).width}.max,rect.width].min h = self.text_size(text[0]).height hmax = [h*text.size,rect.height].min y = rect.y+(rect.height-hmax)/2 x = align==0 ? rect.x : align==2 ? rect.x+rect.width-wmax : rect.x+(rect.width-wmax)/2 text.each_with_index{|t,i| draw_text2(x,y+i*h,wmax,h,t,align) } self end end
捕获.PNG (26.57 KB, 下载次数: 16)
guoxiaomi 发表于 2017-6-18 06:12
会不会是,defined? 的参数是方法调用,而不是方法名(symbol对象),去掉defined?
后面的冒号看看 ...
defined?
defined? expression tests whether or not expression refers to anything recognizable (literal object, local variable that has been initialized, method name visible from the current scope, etc.). The return value is nil if the expression cannot be resolved. Otherwise, the return value provides information about the expression.
Note that the expression is not executed.
p defined?(def x; end) # "expression"
x # error: undefined method or variable
p defined?(@x=1) # "assignment"
p @x # nil
Assignment to a local variable will, however, have the usually result of initializing the variable to nil by virtue of the assignment expression itself:
p defined?(x=1) # assignment
p x # nil
In most cases, the argument to defined? will be a single identifier:
def x; end
p defined?(x) # "method"
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |