Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "set" keyword mean in ruby?

I'm going through the capistrano handbook

https://github.com/leehambley/capistrano-handbook/blob/master/index.markdown

And see the keyword "set" appear

set :deploy_via, :remote_cache

Does set in this example set the symbol :deploy_via to :remote_cache?

like image 606
user784637 Avatar asked Dec 09 '13 17:12

user784637


3 Answers

That's not a keyword in standard Ruby. It's an example of an element in a Domain Specific Language (DSL).

Basically, a DSL allows you to work at a higher level of abstraction by providing more targeted constructs than a general-purpose language like Ruby. The "set" here is an example of this. It's probably just a function in Ruby that you're actually calling, but when you use it, it feels more like a language construct in its own right. Ruby is particularly good at writing DSLs

As for what this does in Capistrano, I have no idea, I've never used Capistrano. :)

like image 123
dsw88 Avatar answered Sep 20 '22 13:09

dsw88


set is not ruby keyword in capistrano command
from capistrano source

 def set(key, value)
   @properties[key] = value
 end
like image 22
Philidor Avatar answered Sep 17 '22 13:09

Philidor


set has no particular meaning in Ruby. In fact, it's not a Ruby keyword, it's a Capistrano command, part of the Capistrano DSL.

Technically speaking, it's a Ruby method. You can see the method definition.

def set(key, value)
  config[key] = value
end
like image 41
Simone Carletti Avatar answered Sep 17 '22 13:09

Simone Carletti