我这样做有什么不同
class T
def initialize
self.class.class_eval do
def test
return self.class.object_id
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
和
class T
def initialize
singleton_class.class_eval do
def test
return self.class.object_id
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
谢谢
PS.Tass回答说,在这个例子中,singleton_class将为每个新对象返回一个不同的object_id,因为singleton_class只属于一个Object.但IRB接下来会说明
1.9.2p180 :001 > class T
1.9.2p180 :002?>
1.9.2p180 :003 > def initialize
1.9.2p180 :004?> singleton_class.class_eval do
1.9.2p180 :005 > def test
1.9.2p180 :006?> return self.class.object_id
1.9.2p180 :007?> end
1.9.2p180 :008?> end
1.9.2p180 :009?> end
1.9.2p180 :010?>
1.9.2p180 :011 > end
=> nil
1.9.2p180 :012 > t = T.new …
Run Code Online (Sandbox Code Playgroud) 我正在使用Cloud Storage for Firebase,无法弄清楚如何访问存储文件
根据https://firebase.google.com/docs/storage/web/start官方指南和https://firebase.google.com/docs/storage/web/create-reference,此代码应返回根引用
let admin = require('firebase-admin')
admin.initializeApp({...})
let storageRef = admin.storage().ref()
Run Code Online (Sandbox Code Playgroud)
但这引发了错误
TypeError:admin.storage(...)。ref不是一个函数
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {...},
"dependencies": {
"@google-cloud/storage": "^1.5.1",
"firebase": "^4.8.0",
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",
"pdfkit": "^0.8.3",
"uuid": "^3.1.0"
},
"private": true
}
Run Code Online (Sandbox Code Playgroud)
节点-v => v7.7.4
我的最终目标是下载文件或将pdf文件上传到存储。
我几个月来就注意到了这一点,但直到现在我才没有时间处理它。每当我的 CI 服务器自动执行git pull
并重新启动 Rails 服务器时,它们schema.rb
都会被随机修改。如下例所示,api_name
某个表的列被删除。大约三个月前我放弃了这个专栏。与 相同transportation_charges
。通常,该文件中的间距会发生变化:请参阅created_at
和updated_at
。
这尤其令人烦恼,因为在下次运行时,当我的 CI 执行初始操作时git pull
,它会抱怨更改schema.rb
并停止执行,直到它们被推送或恢复。而且不仅仅是 CI 服务器。我也在其他开发者机器上看到过这种情况。以前有人遇到过这个吗?
diff --git a/db/schema.rb b/db/schema.rb
index 470d3bf..166e3ee 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -883,7 +883,6 @@ ActiveRecord::Schema.define(version: 20170720211740) do
create_table "ups_package_service_options", force: :cascade do |t|
t.string "name"
- t.string "api_name"
t.string "type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@@ -910,9 +909,8 @@ ActiveRecord::Schema.define(version: 20170720211740) do
t.string "code"
t.string "name"
t.string …
Run Code Online (Sandbox Code Playgroud) const puppeteer = require('puppeteer');
const browser = await puppeteer.launch();
const page = await browser.newPage();
Run Code Online (Sandbox Code Playgroud)
这个有效
await page.goto('https://example.com');
Run Code Online (Sandbox Code Playgroud)
这不起作用(没有协议,即 http/https)
await page.goto("www.example.com');
Run Code Online (Sandbox Code Playgroud)
它抛出错误
协议错误 (Page.navigate):无法导航到无效 URL
为什么它不像我们在 Google Chrome 中打开时那样附加协议?
我使用asciidoctor-pdf
将adoc文档转换为pdf,但总是出现“不是已知字体”的错误,在命令行后添加--trace时,错误是
`initialize': is not a known font. (Prawn::Errors::UnknownFont)
/usr/local/lib/ruby/gems/2.4.0/gems/prawn-2.2.2/lib/prawn/font/afm.rb:53:in `initialize': is not a known font. (Prawn::Errors::UnknownFont)
from /usr/local/lib/ruby/gems/2.4.0/gems/prawn-2.2.2/lib/prawn/font.rb:301:in `new'
from /usr/local/lib/ruby/gems/2.4.0/gems/prawn-2.2.2/lib/prawn/font.rb:301:in `load'
from /usr/local/lib/ruby/gems/2.4.0/gems/prawn-2.2.2/lib/prawn/font.rb:253:in `find_font'
from /usr/local/lib/ruby/gems/2.4.0/gems/prawn-2.2.2/lib/prawn/font.rb:57:in `font'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-pdf-1.5.0.alpha.16/lib/asciidoctor-pdf/prawn_ext/extensions.rb:196:in `font'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-pdf-1.5.0.alpha.16/lib/asciidoctor-pdf/converter.rb:2930:in `theme_font'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-pdf-1.5.0.alpha.16/lib/asciidoctor-pdf/converter.rb:544:in `convert_admonition'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-pdf-1.5.0.alpha.16/lib/asciidoctor-pdf/converter.rb:118:in `convert'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/abstract_block.rb:70:in `convert'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/abstract_block.rb:79:in `block in content'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/abstract_block.rb:79:in `map'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/abstract_block.rb:79:in `content'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/block.rb:110:in `content'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-pdf-1.5.0.alpha.16/lib/asciidoctor-pdf/converter.rb:134:in `convert_content_for_block'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-pdf-1.5.0.alpha.16/lib/asciidoctor-pdf/converter.rb:479:in `convert_preamble'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-pdf-1.5.0.alpha.16/lib/asciidoctor-pdf/converter.rb:118:in `convert'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/abstract_block.rb:70:in `convert'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/abstract_block.rb:79:in `block in content'
from /usr/local/lib/ruby/gems/2.4.0/gems/asciidoctor-1.5.6.1/lib/asciidoctor/abstract_block.rb:79:in `map'
from …
Run Code Online (Sandbox Code Playgroud)