- 20分钟入门:https://www.ruby-lang.org/zh_cn/documentation/quickstart/4/
- 编辑器选择:https://ruby-china.org/wiki/tools
- 选择编辑器并下载安装:https://macromates.com/download
- demo
点击查看代码
#!usr/bin/env ruby
class MegaGreeter
attr_accessor :names
# Create the object
def initialize(names = "world")
@names = names
end
# Say hi to everybody
def say_hi
if @names.nil?
puts "..."
elsif @names.respond_to?("each")#是否响应迭代函数
@names.each do |name| #each循环
puts "A:Hello #{name}!"
end
else
puts "B:Hello #{@names}!"
end
end
def say_bye
if @names.nil?
puts "..."
elsif @names.respond_to?("join")
puts "A:Goodbyte #{@names.join(", ")}. Come back soon}"
else
puts "B:Goodbye #{@names}. Come back soon."
end
end
end
if __FILE__ == $0
mg = MegaGreeter.new
mg.say_hi
mg.say_bye
mg.names = "Zeke"
mg.say_hi
mg.say_bye
mg.names = ["LV","dsa","dsa","dasdas","HH"]
mg.say_hi
mg.say_bye
mg.names = nil
mg.say_hi
mg.say_bye
end