Skip to content

Instantly share code, notes, and snippets.

@bennylope
Created October 16, 2012 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennylope/3902361 to your computer and use it in GitHub Desktop.
Save bennylope/3902361 to your computer and use it in GitHub Desktop.
if CONF.has_key?("mounts")
for folder in CONF['mounts']
config.vm.share_folder(folder['name'], folder['virtual'], folder['host'], :nfs => true)
end
end
@bennylope
Copy link
Author

What's the best Ruby-like way of writing the above Ruby code, given a hash called "CONF" which will load a hash called "mounts" if it exists in the CONF hash?

{
    "mounts": [
        {
            "name": "A name",
            "virtual": "/var/code",
            "host": "~/bode"
        },
        {
            "name": "Another name",
            "virtual": "/var/blah",
            "host": "~/blah"
        }
    ]
}

@bennylope
Copy link
Author

Got my answer. Small change, using the each method. (Thanks to @guillec.)

if CONF.has_key?("mounts")
    CONF['mounts'].each do |folder|
        config.vm.share_folder(folder['name'], folder['virtual'], folder['host'], :nfs => true)
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment