5 回答
TA贡献2021条经验 获得超8个赞
在看Selenium源代码的时候, 发现了获取操作系统的更好方法
def os
@os ||= (
host_os = RbConfig::CONFIG['host_os']
case host_os
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
:windows
when /darwin|mac os/
:macosx
when /linux/
:linux
when /solaris|bsd/
:unix
else
raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
end
)
end
之前用的方法是假定是windows, 如果不是的话根据异常处理来判断是否是Mac
TA贡献1813条经验 获得超2个赞
有一个叫methods()的方法,比如Array.methods()
--------------------------------------------------------- Object#methods
obj.methods => array
------------------------------------------------------------------------
Returns a list of the names of methods publicly accessible in
_obj_. This will include all the methods accessible in _obj_'s
ancestors.
class Klass
def kMethod()
end
end
k = Klass.new
k.methods[0..9] #=> ["kMethod", "freeze", "nil?", "is_a?",
"class", "instance_variable_set",
"methods", "extend", "<em>send</em>", "instance
_eval"]
k.methods.length #=> 42
TA贡献1772条经验 获得超5个赞
代码如下:
[ruby] view plaincopy
class Object
def abc
p "instance abc"
end
def self.abc
p "class abc"
end
end
- 5 回答
- 0 关注
- 970 浏览
添加回答
举报