我是Ruby的新手,并试图学习它.我正在使用最新的Ruby版本(2.4.1)和交互式Ruby Shell.
我children在Dir课堂上遇到过这个方法.我试过文档中的例子:
Dir.children("testdir") #=> ["config.h", "main.rb"]
Run Code Online (Sandbox Code Playgroud)
但它似乎不起作用,因为我收到以下消息:
undefined method `children' for Dir:Class
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
I\xe2\x80\x99m 使用 Mac OS Big Sur 和 rvm
\n$ rvm -v\nrvm 1.29.12-next (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]\nRun Code Online (Sandbox Code Playgroud)\n我安装了 Ruby 2.7.5 版本,并想安装 3.1 版本。我试过
\n$ rvm install 3.1\nUnknown ruby string (do not know how to handle): ruby-3.1.\nUnknown ruby string (do not know how to handle): ruby-3.1.\nSearching for binary rubies, this might take some time.\nNo binary rubies available for: osx/11.6/x86_64/ruby-3.1.\nContinuing with compilation. Please read \'rvm help mount\' to get more information on binary rubies.\nChecking …Run Code Online (Sandbox Code Playgroud) 我有一个数据库:

正如你在'desc'列中看到的那样,文本的长度是可变的(意味着我从这个数据库中拉出的两个字符串的长度不会相同).我最终会在这个数据库中添加更多的条目,但这正是我正在测试的并且从此开始.
现在,我有以下python代码来获取这些字符串块并显示它们:
cmd = input(Enter command:)
sql = "SELECT cmd,`desc` FROM table WHERE cmd = '"+ cmd +"'"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print("Command: "+ row[0] +":\n")
print("Description: "+ row[1][:40] +"\n")
if (len(row[1]) > 40):
print(row[1][40:85])
if (len(row[1]) > 85):
print(row[1][85:130])
if (len(row[1]) > 130):
print(row[1][130:165])
if (len(row[1]) > 165):
print(row[1][165:])
Run Code Online (Sandbox Code Playgroud)
这里的分裂在某种程度上起作用,例如:
命令:close:
说明:此命令将
在消息窗口中为调用字符创建"关闭"按钮
.如果屏幕上当前没有窗口,则
脚本执行将结束.
正如您在上面的输出示例中所看到的,拆分会导致某些字符在中间字中被切断.鉴于字符串可以是总共20个字符和高达190ish之间的任何长度,并且我想将字符串分成几个字块...因为空间限制每个字8个字,我怎么去关于这样做?
GitHub的高级搜索是可以的,但OpenGrok有一些理想的功能.
要使用OpenGrok和GitHub托管的repo,我必须:
或者还有另一种方式吗?
假设我想使用glyphicon作为表单的提交按钮.我该怎么做呢?
详细说明,我不希望传统按钮的"可见"元素.只是一个glyphicon,因为它通常会出现在文本中.
我已经尝试过使用<button>和<input type='button'>使用glyphicon类,并且(正如人们所期望的那样),没有运气.
好吧,我有一个必须在shell=True模式下执行的命令.
os.system 要么 subprocess.Popen(..., shell=True)
此命令包含字符串替换,如: cmd = "some_secret_command {0}".format(string_from_user)
我想要逃避string_from_user变量来防止任何注射.
简单的错误答案:
shlex.quote- 不正确print(shlex.quote('file.txxt; &ls . #'))- > 'file.txxt; &ls . #'(注射)
例:
> python -c "import sys; print(sys.argv[1])" 'file.txxt; &ls . #'
secret.txt
secret2.txt
Run Code Online (Sandbox Code Playgroud)
^- 不正确 例:
import os
CMD = '''string with spaces'''.replace('', '^').replace('^"', '')
os.system('python -c "import sys; print(sys.argv[1])" {0}'.format(CMD))
Run Code Online (Sandbox Code Playgroud)
现在我可以使用 (space) and inject more then one argument.
^和"或'- 不正确 …当我尝试在我的 mac 上安装 cocoapods 时,我安装了 ruby,如下所示:
$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
Run Code Online (Sandbox Code Playgroud)
但是当我输入 command 时sudo gem install cocoapods,它显示错误:
ERROR: Loading command: install (LoadError)
dlopen(/usr/local/Cellar/ruby/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/openssl.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
Referenced from: /usr/local/Cellar/ruby/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/openssl.bundle
Reason: image not found - /usr/local/Cellar/ruby/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/openssl.bundle
ERROR: While executing gem ... (NoMethodError)
undefined method invoke_with_build_args' for nil:NilClass
$ ruby reinstall
ruby: No such file or directory -- reinstall (LoadError)
Run Code Online (Sandbox Code Playgroud)
我是 ruby 的新手,也许它说缺少 openssl.bundle?
当我试图推送到GitHub时,我收到以下错误:
remote: You must verify your email address.
remote: See https://github.com/settings/emails.
fatal: unable to access 'https://github.com/user/userRep.git/': The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)
我绝对相信我的电子邮件已经过验证.我试图添加没有.git的远程URL,但它没有帮助.
我正在使用Ruby 2.3.4和rspec 3.6.0.
我正在为一个使用的对象编写测试rand(10000..99999).我找不到任何文档rand来查看它所属的对象.我尝试了stubbing Kernel,Object和Random(见下文),但我的尝试都没有导致rand对象的存根.
allow(Kernel).to receive(rand).and_return(12345)
allow(Object).to receive(rand).and_return(12345)
allow(Random).to receive(rand).and_return(12345)
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
安装 ruby 2.6.6 时出现此错误:
Error running '__rvm_make -10'
please read /home/.rvm/log/1642694273_ruby-2.6.6/make.log
There has been an error while running make. Halting the installation.
Run Code Online (Sandbox Code Playgroud)
我尝试重新安装 rvm 但这没有任何改变。
其他 ruby 版本安装得很好。