Guest User

Untitled

a guest
Oct 5th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.67 KB | None | 0 0
  1. module ControllerMethods
  2.   def self.included(base)
  3.     base.extend(ClassMethods)
  4.   end
  5.  
  6.   module ClassMethods
  7.     def class_get_config(key)
  8.       -> { puts "#{key} #{self}" }
  9.     end
  10.   end
  11.  
  12.   def public_instance_get_config(key)
  13.     -> { puts "#{key} #{self}" }
  14.   end
  15.  
  16.   private
  17.  
  18.   def private_instance_get_config(key)
  19.     -> { puts "#{key} #{self}" }
  20.   end
  21.  
  22.   def apply_config(key)
  23.     self.class.class_get_config(key).call
  24.     self.public_instance_get_config(key).call
  25.     self.instance_exec &private_instance_get_config(key)
  26.   end
  27. end
  28.  
  29. class MyController
  30.   include ControllerMethods
  31.  
  32.   def test
  33.     apply_config :param
  34.   end
  35. end
  36.  
  37. MyController.new.test
Add Comment
Please, Sign In to add comment