class Abc
attr_accessor :words
def initialize(words = "12345")
@words = words
end
def aaa
if @words.nil?
puts "..."
end
if @words.respond_to?("each")
@words.each do |a|
puts "Hello #{a}!"
end
else
puts "Hello #{@names}!"
end
end
def bbb
if @words.nil?
puts "..."
elseif @words.respond_to?("each")
@words.each do |a|
puts "Hello #{a}"
end
else
puts "error"
end
end
end
k = Abc.new
k.words = ["a","b","c","d"]
k.aaa
k.bbb
以上代码k.aaa 和k.bbb执行的结果为什么不一样?
牛魔王的故事
相关分类