如何把提取出来的 hash.dig('media_info', 'format', 'duration')
再相加,得出一个总数呢?
👍,简洁了好多。我以为 $2
需要转换成 String
才能用 gsub
方法。
移除第二个循环,具体是指?
现在又拍支持一键申请 Let’s Encrypt 证书,并且能够自动续期,还蛮不错的。
#93 楼 @huacnlee 貌似服务器是不是有问题,请求超时了
☁ ~ http head https://gems.ruby-china.org/specs.4.8.gz
http: error: Request timed out (30s).
I, [2016-03-16T12:38:09.627165 #37] INFO -- : > gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
I, [2016-03-16T12:39:38.621329 #37] INFO -- : Error fetching https://gems.ruby-china.org/:
server did not return a valid file (https://gems.ruby-china.org/specs.4.8.gz)
I, [2016-03-16T12:39:38.622425 #37] INFO -- : Terminating async processes
I, [2016-03-16T12:39:38.622530 #37] INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main pid: 66
I, [2016-03-16T12:39:38.622655 #37] INFO -- : Sending TERM to exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 194
2016-03-16 12:39:38 UTC [66-2] LOG: received fast shutdown request
2016-03-16 12:39:38 UTC [66-3] LOG: aborting any active transactions
2016-03-16 12:39:38 UTC [73-2] LOG: autovacuum launcher shutting down
2016-03-16 12:39:38 UTC [70-1] LOG: shutting down
194:signal-handler (1458131978) Received SIGTERM scheduling shutdown...
194:M 16 Mar 12:39:38.652 # User requested shutdown...
194:M 16 Mar 12:39:38.653 * Saving the final RDB snapshot before exiting.
2016-03-16 12:39:38 UTC [70-2] LOG: database system is shut down
194:M 16 Mar 12:39:38.710 * DB saved on disk
194:M 16 Mar 12:39:38.710 # Redis is now ready to exit, bye bye...
FAILED
--------------------
RuntimeError: gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ failed with return #<Process::Status: pid 287 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:105:in `spawn'
exec failed with the params {"cmd"=>["gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/"]}
4d3a9a5937702a71e03afd53cf92ca6870fe1ddfb48c225852659f158375a719
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one
yes,we can 的梗好像没人笑嘛
#2 楼 @king1990_cool 我吧 subt() 方法里的两个 puts 去掉,程序通了...
#2 楼 @king1990_cool 我刚测试了,确实为空,为啥呢,没搞明白。subt('123'') 的返回值应该是字符串,把字符串赋给一个变量,然后输出,应该还是字符串本身才对吧。设计了一个验证的方法对比下:
irb(main):001:0> def test(x)
irb(main):002:1> x = x + 1
irb(main):003:1> end
=> nil
irb(main):004:0> test(3)
=> 4
irb(main):005:0> t = test(3)
=> 4
irb(main):006:0> puts t
4
=> nil
irb(main):007:0>
调试了一下,发现调用了,但是只调用了前半句,后半句没执行,语法问题?
#5 楼 @blacktulip 非常感谢,这个方法简洁多了。
#4 楼 @africwildman 确实是的,有回车,我是先转成数据,把域名单独提取出来。
解决了,虽然丑陋,但是至少能运行了:)
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-
require 'net/dns'
def dig_dns(url)
packet = Net::DNS::Resolver.start("#{url}")
packet.answer
end
filename = ARGV[0]
file = File.open(filename)
file.each_line do |line|
p dig_dns(line.split("\n")[0])[0]
end
file.close
#1 楼 @lyfi2003 感谢回复,把方法放到前面之后,确实没有上面的报错了,但是程序还是没通。
#!/usr/bin/ruby
# -*- coding: UTF-8 -*-
require 'net/dns'
def dig_dns(url)
packet = Net::DNS::Resolver.start("#{url}")
packet.answer
end
filename = ARGV[0]
file = File.open(filename)
file.each_line do |line|
p dig_dns("#{line}")[0]
end
file.close
修改之后,执行提示「参数错误」,没看出来错在哪里,能否指点一下?
/Library/Ruby/Gems/2.0.0/gems/net-dns-0.8.0/lib/net/dns/resolver.rb:1227:in `valid?': Invalid domain name i.yousjz.com (ArgumentError)
from /Library/Ruby/Gems/2.0.0/gems/net-dns-0.8.0/lib/net/dns/resolver.rb:1132:in `make_query_packet'
from /Library/Ruby/Gems/2.0.0/gems/net-dns-0.8.0/lib/net/dns/resolver.rb:968:in `query'
from /Library/Ruby/Gems/2.0.0/gems/net-dns-0.8.0/lib/net/dns/resolver.rb:871:in `search'
from /Library/Ruby/Gems/2.0.0/gems/net-dns-0.8.0/lib/net/dns/resolver.rb:134:in `start'
from chongfu.rb:10:in `dig_dns'
from chongfu.rb:20:in `block in <main>'
from chongfu.rb:19:in `each_line'
from chongfu.rb:19:in `<main>'