在JavaScript中,您可以:
setInterval(func,delay);
Run Code Online (Sandbox Code Playgroud)
我似乎无法在谷歌上找到我正在寻找的东西.这有红宝石的等价物吗?提前致谢.
我最近一直使用Ruby进行编码,并且来自Python,据我所知,单引号和双引号对代码的工作方式没有任何影响.
我转到Ruby看看它是如何工作的,并调查Ruby和Python之间的相似之处.
我曾使用单引号字符串并注意到这一点:
hello = 'hello'
x = '#{hello} world!'
puts x
Run Code Online (Sandbox Code Playgroud)
它返回'#{hello} world!'而不是'hello world!'.
注意到这一点后,我尝试了双引号,问题得到解决.现在我不确定为什么会这样.
单引号和双引号会改变这个还是因为我的编辑器(Sublime text 3)?如果它在以前的版本中工作方式不同,我也使用Ruby 2.0版.
所以,我是红宝石的新手并且非常好奇.我是从python出来的.在python中,我会这样做,看看字典中是否存在某些内容.
dictionary = dict()
dictionary['key'] = 5
def inDictionary(key):
if key in dictionary:
execute code
else:
other code
Run Code Online (Sandbox Code Playgroud)
对我来说相当简单,另一方面,在红宝石中我该怎么做?我一直在尝试像
dictionary = Hash.new
dictionary['key'] = 5
def isDictionary(key)
if dictionary.has_key?(key)
puts 'has key'
end
end
Run Code Online (Sandbox Code Playgroud)
我得到错误,isDictionary未定义局部变量或方法"字典".我做错了什么,并提前感谢.
红宝石有像pythons eval这样的东西吗?我正在搜索谷歌,我不知道这是我如何搜索但我找不到任何东西或如何使用它,如果有一个
在python我会喜欢这样的
def doEval(object):
return repr(eval(object))
Run Code Online (Sandbox Code Playgroud)
你上面的代码会做在python的闲置或东西,运行doEval("打印('你好’)"),它会打印出"你好",然后返回"无"说这是执行,在红宝石我不介意它不做,但我想要评估
红宝石中有这样的东西吗?谢谢.