soupybionics soupybionics - 1 year ago 105
Ruby Question

Where to learn ruby DSL?

Vagrant.configure(2) do |config|
config.vm.define "chefnode" do |chefnode| = "geerlingguy/ubuntu1604"
chefnode.vm.hostname = 'cnode' "public_network"

config.vm.define "chefserver" do |chefserver| = "geerlingguy/ubuntu1604"
chefserver.vm.hostname = 'cserver' "public_network"

I am badly struggling on the above (vagrant dsl) code. Is this Ruby DSL or plain Ruby or something else? Why is there an "=" sign for and vm.hostname, but not for

Answer Source

first of all it's ruby, which as a language can be very handy when you want to create your own DSL. All DSLs are built using base ruby concepts like blocks (do ... end) - no magic here. In your case we may say it's DSL created by Vagrant owners.

Why do they once use = and an another time not? In this specific case I assume it's caused by fact you have one argument which is a String and is required, and later on yo may pass a hash with different setup options, like in example from documentation.

Vagrant.configure("2") do |config| "forwarded_port", guest: 80, host: 8080

If they wanted to use = they would have to enforce you to pass a Hash in which name key would be required and the rest would be optional, I mean something like this: = { name: "default" }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download