从散列中删除一个键
Delete a key from a hash
我根本不知道 Ruby,但我正在尝试扩展 this Jekyll plugin。作者提到只是从记录中删除密钥。我试过使用 delete
函数,但它似乎不起作用。
这是我的代码:
module Jekyll
module Algolia
module Hooks
def self.before_indexing_each(record, node, context)
record.delete(":gallery")
record
end
end
end
end
我确定我在这里遗漏了一些非常简单的东西,但任何想法都会很棒。散列如下所示:
{:html=>"<p>Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).</p>", :content=>"Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).", :headings=>[], :custom_ranking=>{:position=>0, :heading=>100}, :title=>"Captain Brieux", :membership=>"Unconfirmed", :portrait=>"/gallery/members/captain-brieux/portrait.jpg", :attractions=>["_attractions/skipper-canteen.md"], :parks=>["Magic Kingdom", "Disneyland Paris"], :gallery=>[], :collection=>"members", :tags=>[], :categories=>[], :excerpt_html=>"<p>Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).</p>", :excerpt_text=>"Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).", :slug=>"captain-brieux", :type=>"document", :url=>"/sea/members/captain-brieux"}
您在代码中遇到的问题是您将符号作为字符串发送,只需从删除参数中删除“”
module Jekyll
module Algolia
module Hooks
def self.before_indexing_each(record, node, context)
record.delete(:gallery)
record
end
end
end
end
我根本不知道 Ruby,但我正在尝试扩展 this Jekyll plugin。作者提到只是从记录中删除密钥。我试过使用 delete
函数,但它似乎不起作用。
这是我的代码:
module Jekyll
module Algolia
module Hooks
def self.before_indexing_each(record, node, context)
record.delete(":gallery")
record
end
end
end
end
我确定我在这里遗漏了一些非常简单的东西,但任何想法都会很棒。散列如下所示:
{:html=>"<p>Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).</p>", :content=>"Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).", :headings=>[], :custom_ranking=>{:position=>0, :heading=>100}, :title=>"Captain Brieux", :membership=>"Unconfirmed", :portrait=>"/gallery/members/captain-brieux/portrait.jpg", :attractions=>["_attractions/skipper-canteen.md"], :parks=>["Magic Kingdom", "Disneyland Paris"], :gallery=>[], :collection=>"members", :tags=>[], :categories=>[], :excerpt_html=>"<p>Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).</p>", :excerpt_text=>"Captain Brieux is a character in the 1974 film, The Island at the Top of World. Portrayed by Jacques Marin, he is a French inventor who pilots an expedition in a French dirigible name the Hyperion (a model can be found at Disneyland Paris).", :slug=>"captain-brieux", :type=>"document", :url=>"/sea/members/captain-brieux"}
您在代码中遇到的问题是您将符号作为字符串发送,只需从删除参数中删除“”
module Jekyll
module Algolia
module Hooks
def self.before_indexing_each(record, node, context)
record.delete(:gallery)
record
end
end
end
end