这是我的简单期望脚本:
#!/usr/local/bin/expect
puts "Argu 1 : [lindex $argv 0]"
Run
---
expect example.expt Testing
Output
------
Argu 1: Tesing
Run Code Online (Sandbox Code Playgroud)
我需要计算命令行传递的参数。像这样:
expect example.expt 1 2 3 4
I need the script for the following output
Total: 4 arguments
Arg1: 1
Arg2: 2
Arg3: 3
Arg4: 4
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?谢谢!
这是我的文件夹结构.
/ home/files/encounter 9-22-11-0.jpg ../home/files/encounter 9-22-11- [n] .jpg
puts Dir.glob("/home/files/*.jpg")[0]
Run Code Online (Sandbox Code Playgroud)
当我执行上面的代码时,它显示第六个文件(索引5 =>/home/files /遇到9-22-11-5.jpg),但实际上我需要输出作为第一个文件(索引0 =>/home/files/encounter 9-22-11-0.jpg)
如何将文件排序为用户定义的排序顺序?喜欢
当我尝试..
.. [0] =>/home/files/encounter 9-22-11-5.jpg
.. [1] =>/home/files/encounter 9-22-11-21.jpg
.. [2] =>/home/files/encounter 9-22-11-39.jpg
但是,我需要
.. [0] =>/home/files/encounter 9-22-11-0.jpg
.. [1] =>/home/files/encounter 9-22-11-1.jpg
.. [2] =>/home/files/encounter 9-22-11-2.jpg
附加信息,排序也不起作用.
f = Dir.glob("/ home/files/*.jpg").排序
f [0] =>/home/files/encounter 9-22-11-0.jpg
f [0] =>/home/files /遇到9-22-11-1.jpg
f [0] =>/home/files/encounter 9-22-11-10.jpg
f [0] =>/home/files/encounter 9-22-11- 11.JPG
如何显示图像,该图像存储在项目目录的外部.
I'm struggling to wrap my mind around an ActiveRecord query.
I'm trying to search my database for GolfRetailer objects with ID's 1..100, that have something (not nil) in their :website field, and that don't have true in their duplicate_domain field.
Here's the query I expected to work:
GolfRetailer.where.not(website: nil, duplicate_domain: true).where(id: 1..100)
I also tried this variant of essentially the same query: GolfRetailer.where.not(website: nil).where(id: 1..100, duplicate_domain: !true)
But both return an empty array, despite there definitely being records that …
我有一个像下面这样的文件夹结构.
-FOO
-BAG
Rose.TXT
-BAR
JaCk.txt
-foo
-bag
rose.txt
-bar
jack.txt
我需要使用ruby生成数字组合.例如 :
arr = [1,2,3,4,5]
约束是,组合号应包括数字5,长度最小为3或更高.(即125,521,1245等......).上述数组元素(值1至5)可以在组合数中出现一次或两次或更多次.
我有这样的字符串,
str = "uu@p, xx@m, yy@n, zz@m"Run Code Online (Sandbox Code Playgroud)
我想知道如何将给定的字符串转换为哈希.(即我的实际要求是,有多少个值(在@符号之前)有m,n和p.我不想计算,我需要一个确切的值).输出会更好,像这样,
{"m" => ["xx", "zz"], "n" => ["yy"], "p" => ["uu"]}Run Code Online (Sandbox Code Playgroud)
可以帮帮我吗?
你能帮助任何人吗?我有一个哈希值如下.我需要按键值以相反的顺序对哈希进行排序,并返回哈希类型.
我的实际预期输出是(哈希)
result = {20111104111221=>[4, 5, 6], 20111104111220=>[7, 8, 9], 20111104110950=>[1, 2, 3]}
Run Code Online (Sandbox Code Playgroud)
# this is my input
irb(main):096:0> h = {20111104111221=>[4, 5, 6], 20111104110950=>[1, 2, 3], 20111104111220=>[7, 8, 9]}
=> {20111104111221=>[4, 5, 6], 20111104110950=>[1, 2, 3], 20111104111220=>[7, 8, 9]}
# It's not correct
irb(main):095:0> Hash[h.sort]
=> {20111104111221=>[4, 5, 6], 20111104110950=>[1, 2, 3], 20111104111220=>[7, 8, 9]}
Run Code Online (Sandbox Code Playgroud)
所以,我试过这个.它是正确的,但它作为数组值返回,我需要一个返回值作为哈希.
# It's correct but it's not a hash
irb(main):092:0> arr = …Run Code Online (Sandbox Code Playgroud) 我有这样的字符串(实际上是日期和时间)"20120207080000".
有没有选择使用任何模式匹配技术或其他任何东西拆分给定的字符串?
即我需要像这样的输出
output = ["2012", "02", "07", "08", "00", "00"]
Run Code Online (Sandbox Code Playgroud)
否则是否可以将给定的字符串转换为日期/时间对象?
红宝石版:1.8.7
我需要使用两个数组创建一个新的Hash对象.
但是,条件是第一个数组值应该是Hash的键值,第二个数组值应该是Hash值.
a = ["x", "y"]
b = [2, 4]
Run Code Online (Sandbox Code Playgroud)
结果应该是: c = {"x" => 2, "y" => 4}
ruby ×9
hash ×3
arrays ×2
sorting ×2
activerecord ×1
combinations ×1
datetime ×1
expect ×1
image ×1
math ×1
merge ×1
natural-sort ×1
reverse ×1
split ×1
string ×1