Hello, good folk of ruby-talk.
I was wondering whether there’s a Ruby
idiom to mass-populate keys of a Hash.
I’m coding a graph class supporting labeled vertices, and I want to
represent this relationship as a @vertices Hash, with keys being the
actual vertices and values being their labels – initially all nil:
class Graph
def initialize enum
@vertices = {}
enum.each { |vertex| @vertices[vertex] = nil }
end
end
Is there a more elegant way to take an enum
and turn it into nil-referencing Hash keys?
— Shot