p method in Ruby hard to search for

隐身守侯 提交于 2019-12-30 17:16:32

问题


I'm trying to find info on the p method in Ruby. It seems to produce internal info on the properties of a class but when I try to search for it I get every word that has the letter "p" in it.


回答1:


Have you seen the api doc page? http://www.ruby-doc.org/core/Kernel.html#method-i-p

There's also http://apidock.com/ruby/Kernel/p




回答2:


Each method you can call "directly", e.g: print, p, abort, puts, readline, etc., is located in the Kernel class.


(Kernel.methods - Object.methods).sort.each do |method|
   puts method
end



回答3:


You can find more information about the p method from the Ruby documentation of the Kernel module:
http://www.ruby-doc.org/core/Kernel.html#method-i-p

p(obj) → obj

p(obj1, obj2, ...) → [obj, ...]

p() → nil

For each object, directly writes obj.inspect followed by a newline to the program’s standard output.

S = Struct.new(:name, :state)
s = S['dave', 'TX']
p s

produces:

#<S name="dave", state="TX">



回答4:


Do you mean like:

ri Kernel#p



来源:https://stackoverflow.com/questions/623899/p-method-in-ruby-hard-to-search-for

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!