Module: Surrounded::Context::Initializing
- Defined in:
- lib/surrounded/context/initializing.rb
Instance Method Summary collapse
-
#initialize(*setup_args) ⇒ Object
Shorthand for creating an instance level initialize method which handles the mapping of the given arguments to their named role.
- #new(*args, &block) ⇒ Object
Instance Method Details
#initialize(*setup_args) ⇒ Object
Shorthand for creating an instance level initialize method which handles the mapping of the given arguments to their named role.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/surrounded/context/initializing.rb', line 12 def initialize(*setup_args) private_attr_reader(*setup_args) mod = Module.new line = __LINE__ mod.class_eval " def initialize(#{setup_args.join(',')}) arguments = method(__method__).parameters.map{|arg| eval(arg[1].to_s) } @role_map = RoleMap.new map_roles(#{setup_args}.zip(arguments)) end ", __FILE__, line const_set("ContextInitializer", mod) include mod end |
#new(*args, &block) ⇒ Object
4 5 6 7 8 |
# File 'lib/surrounded/context/initializing.rb', line 4 def new(*args, &block) instance = allocate instance.send(:initialize, *args, &block) instance end |