module Necromancy::Control
Public Class Methods
extended(mod)
click to toggle source
# File lib/necromancy/control.rb, line 78 def self.extended(mod) return unless mod.name and mod.name.start_with? self.name mthname = mod.name.sub("#{self.name}::", '') define_method mthname do |*args, &block| if args.empty? branch { include mod } else branch { include mod; protected *mod.instance_methods }[*args, &block] end end end
Public Instance Methods
[](target, *targets)
click to toggle source
Reveals some methods and Creates some aliases. @param [Symbol] target Reveals a method of the symbol. @param [Hash] target Hides all methods of each key and creates aliases from each value to each key. @param [Array] targets A list of Symbol or Hash that will be processing as target. @return [Control] Processed new {Necromancy::Control} object. @example
require 'necromancy' N = Necromancy.Alternative[:<< => :if, :>> => :then, :| => :else].new puts (1..100).map &( (N%15).zero? .then(proc{"FizzBuzz"}) .else \ (N%3).zero? .then(proc{"Fizz"}) .else \ (N%5).zero? .then(proc{"Buzz"}) .else N )
# File lib/necromancy/control.rb, line 50 def [](target, *targets) targets.unshift(target) names = targets.select { |t| t.is_a? Symbol } aliases = targets.select { |t| t.is_a? Hash }.inject(:merge) || {} branch do public *names aliases.each do |org, als| alias_method(als, org) protected org public als end end end
call(*targets)
click to toggle source
@deprecated
# File lib/necromancy/control.rb, line 20 def call(*targets) warn <<EOF Necromancy.Hoge.() deprecated. Use Necromancy.Hoge(). EOF branch { protected *instance_methods }[*targets] end
hiding(name, *names)
click to toggle source
Hides some methods. @param [Symbol] name Hides a method of the name. @param [Array] names A list of a Symbol that will be processing as name. @return [Control] Processed new {Necromancy::Control} object. @example
require 'necromancy' N = Necromancy.Alternative.hiding(:*, :**).new ary = [1, nil, 2, nil, 3] ary.map &(N | proc{0}) * 10 # => [10, 0, 20, 0, 3]
# File lib/necromancy/control.rb, line 73 def hiding(name, *names) names.unshift(name) branch { protected *names } end
new()
click to toggle source
Creates a {Necromancy::Necromancy} object including the {Necromancy::Control}. @return [Necromancy]
# File lib/necromancy/control.rb, line 7 def new mod = self Class.new(::Necromancy::Necromancy) { include mod }.new end
using(*targets)
click to toggle source
@deprecated
# File lib/necromancy/control.rb, line 29 def using(*targets) warn <<EOF Necromancy.Hoge.using() deprecated. Use Necromancy.Hoge[]. EOF self[*targets] end
Private Instance Methods
branch(&block)
click to toggle source
# File lib/necromancy/control.rb, line 12 def branch(&block) mod = self Module.new { include mod; extend Control; module_eval(&block) } end