新手问题 关于 inspect 方法

drine · November 04, 2014 · Last by DrinE replied at November 05, 2014 · 4108 hits

1.能稍微讲下 inspect 的作用么.. 2.为什么改后输出结果有下面那个差别 3.在 ruby doc 里说 inspect 方法是,通过字符返回这个环境的内容。感觉不太理解这句话呢...求解释一下 4.谢谢了! flash = { success: "It worked!", error: "It failed." } flash.each do |key, value| puts "Key #{key} has value #{value}" end

输出: Key :success has value "It worked!" Key :error has value "It failed."

flash = { success: "It worked!", error: "It failed." } flash.each do |key, value| puts "Key #{key.inspect} has value #{value.inspect}" end

输出: Key success has value It worked! Key error has value It failed.

1 Floor has deleted
You need to Sign in before reply, if you don't have an account, please Sign up first.