Closed ghost closed 10 years ago
Resource#to_hash
is your friend here:
In Rails (or wherever else ActiveSupport
is sold) you can use Hash#slice
.
irb(main)> Octokit.forks('rafalchmiel/friction').first.to_hash.slice(:id, :full_name)
=> {:id=>18761355, :name=>"modsognir/friction"}
Otherwise, you'll need to use select
:
irb(main)> Octokit.forks('rafalchmiel/friction').first.to_hash.select {|k,v| [:id, :full_name].include?(k) }
=> {:id=>18761355, :name=>"modsognir/friction"}
Awesome, thanks a lot :+1:!
Given I have this:
How would I keep certain fields (from an Array such as
[:id, :full_name]
) and delete others from theforks
variable? So all I want to be left with, is aSawyer::Resource
with only the:id
and:full_name
fields.Adding a small method like
delete
to theSawyer::Resource
class would be helpful: