Module: Capistrano::Extensions::Variables
- Included in:
- Server::WebServer
- Defined in:
- lib/capistrano-exts/servers/utils/variables.rb
Instance Method Summary collapse
-
#method_missing(method, *args, &block) ⇒ Object
Instead of defining a whole lot of attr_accessor, let’s be smart about templates, right ?.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Instead of defining a whole lot of attr_accessor, let’s be smart about templates, right ?
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/capistrano-exts/servers/utils/variables.rb', line 11 def method_missing(method, *args, &block) if method =~ /(.+)=$/ # Method 1: works but the attr_accessor would be set on all instances # Which is not good # # self.class.__send__(:attr_accessor, $1.to_sym) # self.__send__(method, *args, &block) # Method 2: Just set the instance variable, works better self.send(:instance_variable_set, "@#{$1.to_sym}", *args) end end |