我做一个gsub交换"bad"的"good".有没有办法使用,capitalize所以它会交换大小写?或者我必须写def两次?
def add_more_ruby(string)
string.gsub('bad','good').capitalize
end
Run Code Online (Sandbox Code Playgroud) 我的语法有问题尝试了一些事情,但仍然没有做到正确.我不明白的是什么?谢谢
change = ['cents', 'pennies', 'coins', 'dimes', 'pence', 'quarters']
change.sort {|anythinghere| a <=> b puts "Ascending #{anythinghere}" }
Run Code Online (Sandbox Code Playgroud) 我正在努力理解理解 OOP。我正在尝试使用 IRB 来玩 Ruby 并加深我的理解。
在 IRB
foo = Object.new
Run Code Online (Sandbox Code Playgroud)
创建一个新对象 但是,如果我尝试给 irb 一个定义并在该对象上调用它,则它不起作用。(def 是否必须发生在 .rb 文件中并加载到 Ruby 中?)
def bar "hello" end
Run Code Online (Sandbox Code Playgroud)