Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Hash
- def leaf_values
- values.flat_map do |v|
- if v.is_a?(Hash)
- v.leaf_values
- else
- [v]
- end
- end
- end
- end
- p({"root"=>{:a=>"tom", :b=>{:c => 1, :x => 2}}}.leaf_values) # => ["tom", 1, 2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement